Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a cell in Excel based on variable containing the row number

Tags:

excel

vba

How would I select a cell based on a variable beginPosition containing the row number. For example if my beginPosition variable is 10, how would I select cell A10?

I tried using the Range function, but that is not working very well (erroring out).

like image 265
rvphx Avatar asked Mar 27 '12 15:03

rvphx


People also ask

How do you reference a cell row number in Excel?

Usage notes. The ROW function returns the row number for a cell or range. For example, =ROW(C3) returns 3, since C3 is the third row in the spreadsheet. When no reference is provided, ROW returns the row number of the cell which contains the formula.

How do you select a variable range in Excel?

To use a range or a single cell as a variable, first, you need to declare that variable with the range data type. Once you do that you need to specify a range of a cell to that variable using the range object. This also gives you access to all the properties and methods that you can use with a range.


2 Answers

Use INDIRECT function

e.g if cell A1 has 4 the function =INDIRECT("C"&A1) will return the contents of cell C4.

http://www.freelists.org/post/mso/ExcelVariable-cell-reference,5

like image 177
kim Avatar answered Sep 23 '22 20:09

kim


Range("A" & beginPosition).Select
like image 21
Francis P Avatar answered Sep 25 '22 20:09

Francis P