应用程序对象定义错误(1004)

时间:2016-10-03 17:02:11

标签: excel vba runtime-error

我正在尝试创建一个在Excel工作表的某个列中创建值的方法。继续在Sheets.Cells.Value = Cint行上运行上面的运行时错误。知道可能是什么问题吗?谢谢!

For Each Cell In Sheets(tab_name).Range(cell_range)
    current_row = Cell.Row
    split_cells = Split(Cell.Value, ".")
    Sheets(tab_name).Cells(current_row, 58).Value = CInt(split_cells(0))
Next Cell

2 个答案:

答案 0 :(得分:0)

单元格必须为空。 Split将为任何非空字符串返回一个数组。

enter image description here 这是一种更简单的编写方式:

For Each Cell In Sheets(tab_name).Range(cell_range)

    With Cell.EntireRow
        If Cell <> "" Then 
            split_cells = Split(Cell.Value, ".")
           .Cells(1, 58).Value = CInt(split_cells(0))
        Else
           .Cells(1, 58).Value = 0
        End If

    End With
Next Cell

答案 1 :(得分:0)

INT(Cell.Value)不足以满足您的目标吗?

相关问题