Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Cell Address needed in Excel VBA

Tags:

excel

vba

I need a relative cell address. i.e. "A2" not "$A$2"

When I use myAddress = Worksheets("Sheet1").Cells(1, 2).Address, myAddress returns $B$2. I actually need the relative value B2.

Why, you ask? I knew you would ask... Because I want to then fill down the formula using that B2 cell address to all of the cells below it. And I don't want each subsequent cell to refer to B2, but C2 then D2 and so on.

like image 462
Kevin Scharnhorst Avatar asked Jul 24 '14 12:07

Kevin Scharnhorst


People also ask

How do you get the cell address of a value in Excel VBA?

Look at the name box. The name is usually the row character followed by the column number, such as cell A1. read more if your active cell is not visible in your window. It will show you the active cell address.

When would you use a relative cell reference in Excel?

Relative cell references are basic cell references that adjust and change when copied or when using AutoFill. Example: =SUM(B5:B8), as shown below, changes to =SUM(C5:C8) when copied across to the next cell. Situations arise in which the cell reference must remain the same when copied or when using AutoFill.

What does .address do in VBA?

Address is used to get the cell address for simple local reference (ex. $A$1) or reference style notation for cell references (ex. A1 or R1C1 format). It can also be used to get the range address which includes the workbook name and worksheet name.


1 Answers

myAddress = Worksheets("Sheet1").Cells(1, 2).Address(False, False)
like image 106
GSerg Avatar answered Oct 14 '22 07:10

GSerg