简体   繁体   中英

Application Object defined error (1004)

I'm trying to create a method that creates a value in a certain column of the excel sheet. Keep running into the runtime error above on the Sheets.Cells.Value = Cint line. Any idea what could be the problem? Thanks!

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

The cell must be empty. Split will return an array for any non-empty string.

在此处输入图片说明 Here is a simpler way to write it:

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

INT(Cell.Value)不能满足您的要求吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM