简体   繁体   English

在Excel(VBA)中按ID获取单元格值

[英]Get Cell value by ID in Excel (VBA)

Good day, I set some IDS to some cells in Excel using this: 美好的一天,我使用以下方法在Excel中的某些单元格中设置了一些IDS:

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. 我不知道这些ID是否已保存,现在我需要获取那些单元格的值,但是通过ID,我不知道如何完成这些操作,我需要它,因为我想获取这些值如果特定单元格更改了位置,请使用它们的ID。希望您理解。

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. 我需要它,是因为如果这样的单元格改变位置,我想使用它们的ID获取特定单元格的值,希望您理解。

For that don't use ID's. 为此,请不要使用ID。 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 您可能还需要阅读更多有关定义命名单元格引用或范围的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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