在 VBA Excel 2007 中将文本转换为数字

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

Convert text to number in VBA Excel 2007

vbaexcel-vbaexcel-2007excel

提问by Sam

Doesn't

没有

Worksheets("Data").Cells(9, 17) + 0#in VBA code convert "6" (or any number stored as text) automatically to number?

Worksheets("Data").Cells(9, 17) + 0#在 VBA 代码中将“6”(或任何存储为文本的数字)自动转换为数字?

If not, do you know of any manner to do the trick? Thank you!

如果没有,你知道有什么方法可以做到这一点吗?谢谢!

采纳答案by Kevin Pope

You can cast the string as a Dboule data type if you need to use it within your code:

如果您需要在代码中使用它,您可以将字符串转换为 Dboule 数据类型:

Dim dbl As Double
dbl = CDbl(ThisWorkbook.Worksheets("Data").cells(9, 17))

回答by Zaider

Try Worksheets("Data").Cells(9,17).NumberFormat = "0".

试试Worksheets("Data").Cells(9,17).NumberFormat = "0"