ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   Help with Newbie question - Cell Reference (https://www.excelbanter.com/new-users-excel/91388-help-newbie-question-cell-reference.html)

[email protected]

Help with Newbie question - Cell Reference
 


When writing a function in a cell, it always refers to that cell,
regardless if it moves. (Rows and columns are inserted) When writing
in VBA how do I make VBA track the cell's movement, so that when I
insert rows and columns with VBA code it is still referring to the
same cell?

Here is what I am using:

MyVAR = Cells(20, 6).Value 'If I insert rows and columns it still
refers to cell 20,6

Thanks in advance for any help with this!

Dave Peterson

Help with Newbie question - Cell Reference
 
You could name that cell (insert|name|define)

Then you could use:

myVar = worksheets("sheet1").range("mynamehere").value



wrote:

When writing a function in a cell, it always refers to that cell,
regardless if it moves. (Rows and columns are inserted) When writing
in VBA how do I make VBA track the cell's movement, so that when I
insert rows and columns with VBA code it is still referring to the
same cell?

Here is what I am using:

MyVAR = Cells(20, 6).Value 'If I insert rows and columns it still
refers to cell 20,6

Thanks in advance for any help with this!


--

Dave Peterson


All times are GMT +1. The time now is 04:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com