vba Excel vba如何划分?

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

Excel vba how to divide?

excelvbaexcel-vba

提问by user3774667

I trying to divide value taked from cells

我试图划分从单元格中获取的值

Dim Sk as integer, P as integer

'Cells(5, 4) = 9
'Cells(5,  14) = 2

Sk = Cells(5, 4) - Cells(5,  14) 
' Sk= 7
P = Sk / Cells(5, "D") ' SK = 7 ' Cells(5, "D") = 15
' P = 0 

But Excel give me P = 0 always if i change divide / by multiple * everithing ok

但是如果我更改除以/乘以多个 * 一切正常,Excel 总是给我 P = 0

Excel want to be P as variant Why this hapens?

Excel 想要 P 作为变体 为什么会发生这种情况?

采纳答案by Snail

Instead of declaring as SKas an Integerdeclare it as a Double

而不是声明为SK作为一个Integer声明为Double