【问题标题】:Assignment of value of one cell to another is not producing the same value in assigment cell将一个单元格的值分配给另一个单元格不会在分配单元格中产生相同的值
【发布时间】:2020-11-15 06:38:52
【问题描述】:

我正在练习将单元格“1.5”的值分配给另一个单元格中的值,但它一直在单元格中放置 2.0。这是我正在使用的代码。

Sub NumberaVariable()

' Declare a Integer Variable, name it "aPrice"
Dim aPrice As Integer
' Have it store the prce information from H3
aPrice = Range("H3").Value
'Paste the price information in C5
Range("C5").Value = aPrice

End Sub

我尝试过使用单元格格式,甚至通过公式测试了 H3 的内容 =+(H3) 在单元格 C5 中,它产生了 1.5 的预期值。我很难理解为什么它会在单元格 H3 中的值上加上 0.5。

谁能帮我理解为什么会这样?

【问题讨论】:

    标签: excel vba variables variable-assignment


    【解决方案1】:

    这个问题的原因是你的变量的数据类型。由于您将其声明为 Integer,因此它将 1.5(浮点数或十进制值)更改为 2(整数)。

    您可以尝试使用Dim aPrice As Single 将其定义为单曲。

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      相关资源
      最近更新 更多