Перейти к содержимому

Откуда в адресе берутся доллары | Where Those Dollar Signs Come From in VBA

Macros Channel

0:00 / 0:00

Откуда в адресе берутся доллары | Where Those Dollar Signs Come From in VBA

151 просмотр · 2 нед. назад
Macros Channel
1,92 тыс. подписчиков
151 просмотр · 2 нед. назад
Подписывайтесь на Дзен «Макрос решает»: https://dzen.ru/macroschannel Телеграм с файлами и дополнительными материалами: https://t.me/macroschannel Курс «Access без программиста»: https://goga.zone/u/macros/p/access-b... Поддержать создание новых гайдов и практических материалов: https://dzen.ru/macroschannel?donate=... Макрос берёт адрес ячейки и возвращает $A$1, хотя вам нужен обычный A1. Ошибки нет, код написан верно. Просто свойство Address по умолчанию отдаёт абсолютную ссылку, и убираются доллары не заменой текста, а двумя аргументами внутри скобок. В этом уроке разбираем свойство Address объекта Range в Excel VBA и учимся получать адрес ячейки или диапазона в нужном формате. На примере ячейки A1 и диапазона A1:C6 смотрим, как управлять абсолютностью ссылки. Первый аргумент RowAbsolute отвечает за знак доллара перед номером строки, второй ColumnAbsolute — за доллар перед буквой столбца. Если оба аргумента равны True, VBA возвращает полностью абсолютный адрес: Range("A1").Address(True, True) $A$1 Range("A1:C6").Address(True, True) $A$1:$C$6 Если второй аргумент поставить в False, доллар останется только перед номером строки. Получится смешанная ссылка: Range("A1:C6").Address(True, False) $A1:$C6 Обратный вариант закрепляет только строку: Range("A1:C6").Address(False, True) A$1:C$6 Если оба аргумента равны False, адрес становится полностью относительным: Range("A1:C6").Address(False, False) A1:C6 Также показываю, что вместо True и False можно писать числовые эквиваленты 1 и 0 — для VBA это одно и то же. Range("A1:C6").Address(1, 0) Отдельно упоминаю остальные аргументы свойства. Третий задаёт стиль ссылок: Address(False, False, xlR1C1) вернёт R1C1:R6C3. Четвёртый добавляет к адресу имя книги и листа, что пригодится при работе с несколькими файлами. После урока вы будете понимать: как получить адрес ячейки через Range.Address; как вернуть адрес целого диапазона; чем отличаются абсолютные, смешанные и относительные ссылки; как управлять знаком доллара отдельно для строки и для столбца; как использовать True/False и 1/0 в аргументах свойства; как переключить адрес в стиль R1C1. #Excel #VBA #ExcelVBA #RangeVBA #RangeAddress #МакросыExcel #VisualBasic #VBAДляНачинающих #УрокиExcel #ExcelДляНачинающих #МакросРешает Your macro returns the address of a cell as $A$1 when all you wanted was A1. There is no error and the code is correct. The Address property simply returns an absolute reference by default, and the dollar signs are removed with two arguments, not with string replacement. In this lesson we explore the Address property of the Excel VBA Range object and learn how to return a cell or range address in the format you need. Using cell A1 and range A1:C6, we look at how to control the reference style. The first argument, RowAbsolute, controls the dollar sign before the row number. The second, ColumnAbsolute, controls the dollar sign before the column letter. With both arguments set to True, VBA returns a fully absolute address: Range("A1").Address(True, True) $A$1 Range("A1:C6").Address(True, True) $A$1:$C$6 Setting the second argument to False keeps the dollar sign in front of the row only, producing a mixed reference: Range("A1:C6").Address(True, False) $A1:$C6 The opposite combination locks the row instead: Range("A1:C6").Address(False, True) A$1:C$6 With both arguments set to False, the address becomes fully relative: Range("A1:C6").Address(False, False) A1:C6 We also cover 1 and 0 as numerical equivalents of True and False — VBA treats them identically. Range("A1:C6").Address(1, 0) The remaining arguments get a brief mention as well. The third one sets the reference style, so Address(False, False, xlR1C1) returns R1C1:R6C3. The fourth adds the workbook and worksheet name to the address, which helps when your macro works across several files. By the end of the lesson you will understand how to retrieve cell and range addresses, control absolute and relative references for rows and columns separately, and switch the output to R1C1 style. #Excel #VBA #ExcelVBA #RangeVBA #RangeAddress #Macros #VisualBasic #ExcelTutorial #LearnVBA #exceltips 🎬 Подпишитесь на YouTube MACROSCHANNEL, если вы работаете с таблицами, отчётами или автоматизацией. У нас: Пошаговые Excel-гайды Макросы с объяснениями Автоматизация без кода Истории Microsoft и офисных программ 🎬 Subscribe to MACROSCHANNEL on YouTube if you work with spreadsheets, reports, or office workflows. We post: Excel step-by-step tutorials Explained macros and VBA code Automation tips (with or without code) Microsoft Office stories and productivity hacks