excel - 如果单元格在vba中有小数点,有没有办法引用?

标签 excel vba

我想在 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/

相关文章:

excel - 如何在 Groovy 中生成 excel 或 pdf 格式的报告?

excel - Excel VBA 中的 "!="相当于什么?

vba - 剪贴板内容类型 Word VBA

excel - 根据输入的行数/列数创建表格

excel - 找到文本vba时代码不返回值

Excel - 在每行中生成三组数字的笛卡尔积

vba - 循环遍历文本框的二维数组

C# 创建 Excel(完成)然后显示/打开它?帮助

arrays - 如何将选定范围复制到给定数组中?

sql - VBA/Visual Basic。简单的字符串 SQL