简体   繁体   中英

Get Cell value by ID in Excel (VBA)

Good day, I set some IDS to some cells in Excel using this:

ActiveCell.id = "whateverID"

I don't know if those IDs are saved, and now I need to get the Values of those Cells but by ID, I don't have any idea on how to get it done, I need it because I want to get the values of specific cells using their IDs if such cells change their position, hope you understand.

Or if you know a better way to get it done the better.

I need it because I want to get the values of specific celss using their IDs if such cells change their position, hope you understand.

For that don't use ID's. Name the cell. For example

ThisWorkbook.Sheets("Sheet1").Range("A1").Name = "whateverID"

Now even if that range moves, you can always use the following to write/read that cell

WRITE

ThisWorkbook.Sheets("Sheet1").Range("whateverID").Value = "Something"

OR

READ

Debug.Print ThisWorkbook.Sheets("Sheet1").Range("whateverID").Value

You might also want to read more about Define named cell references or ranges

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM