vba 根据包含行号的变量在 Excel 中选择一个单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9892838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:50:51  来源:igfitidea点击:

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

excelexcel-vbavba

提问by rvphx

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

我将如何根据beginPosition包含行号的变量选择单元格。例如,如果我的 beginPosition 变量是 10,我将如何选择单元格 A10?

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

我尝试使用 Range 函数,但效果不佳(出错)。

回答by kim

Use INDIRECT function

使用间接函数

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

例如,如果单元格 A1 有 4,则函数 =INDIRECT("C"&A1) 将返回单元格 C4 的内容。

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

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

回答by Francis P

Range("A" & beginPosition).Select