vba 从工作表上的单元格获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32404582/
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 09:56:26  来源:igfitidea点击:

Get Value from a cell on a worksheet

excel-vbavbaexcel

提问by Bob Amick

I'm trying to do what I think is something simple and looks right. What I'm trying to do is pull a value from a cell on a worksheet that is in the current workbook. However, every time I run the code I get the following error: Run-time error'g': Subscript out of range. Below is the listed code that I'm using.

我正在尝试做我认为简单且看起来正确的事情。我想要做的是从当前工作簿中的工作表上的单元格中提取一个值。但是,每次运行代码时都会出现以下错误:运行时错误'g':下标超出范围。下面是我正在使用的列出的代码。

Damp_DL_Height = ThisWorkbook.Sheets("DampType").Cells(3, 3).Value

I've got the variable defined as Double. DampType is equal to the name of the sheet that I'm trying to pull the cell data from. Should I be using some other type of command to get the value?

我已将变量定义为 Double。DampType 等于我试图从中提取单元格数据的工作表的名称。我应该使用其他类型的命令来获取值吗?

Any help is appreciated.

任何帮助表示赞赏。

回答by Raystafarian

Since DampTypeis a string variable, it doesn't need quotation marks -

由于DampType是字符串变量,因此不需要引号 -

Damp_DL_Height = ThisWorkbook.Sheets(DampType).Cells(3, 3).Value