我想在 VBA 中创建一些代码,它将查看 B 列工作表中的单元格。如果代码找到一个带小数的单元格值(与整数相反,例如不是 1,而是 1.1)然后打印单元格值把它放在另一张纸上。
我知道这将是一个循环,它将使用偏移命中等。我没有在 VBA 中尝试过这段代码,我只是将它作为我将在问题中执行的示例输入。
For each cell in Sheets("Sub Tasks").Range("B1:B" & LastRow)
If cell = '(DECIMAL FORUMLA) Then
最佳答案
你可以使用这样的东西:
Dim cell As Range
For Each cell In Sheets("Sub Tasks").Range("B1:B" & LastRow)
If IsNumeric(cell.Value) Then
If Val(cell.Value) <> Int(cell.Value) Then
' The number contains decimals.
Dim valueToTheRight As Variant
valueToTheRight = cell.Offset(0, 1).Value
' TODO: Add `valueToTheRight` into the appropriate place of the other sheet.
End If
Else
' The cell value is not a number.
' TODO: either do something about it or remove the `else` branch to ignore it.
End If
Next
关于excel - 如果单元格在vba中有小数点,有没有办法引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58395275/