循环并检查单元格是否为空 – 未注册单元格为空
这是我的代码:
For Each Cell In NewBook.Sheets(1).Range("T2:T" & lastRow) If Cell.Value = 76 Or Cell.Value = 69 Then MsgBox Cells(Cell.Row, 8).Value If NewBook.Sheets(1).Cells(Cell.Row, 8).Value = "" Then Do Until IsEmpty(NewBook.Sheets(1).Cells(Cell.Row, col).Value) If Not NewBook.Sheets(1).Cells(Cell.Row, col).Value = "" Then col = col + 1 End If Loop NewBook.Sheets(1).Cells(Cell.Row, col) = "Codes 69 or 76 Reported w/ No applicable Bankrupcty Rptd" End If End If col = 50 Next Cell
我也试过:
For Each Cell In NewBook.Sheets(1).Range("T2:T" & lastRow) If Cell.Value = 76 Or Cell.Value = 69 Then MsgBox Cells(Cell.Row, 8).Value If IsEmpty(NewBook.Sheets(1).Cells(Cell.Row, 8).Value) = True Then Do Until IsEmpty(NewBook.Sheets(1).Cells(Cell.Row, col).Value) If Not NewBook.Sheets(1).Cells(Cell.Row, col).Value = "" Then col = col + 1 End If Loop NewBook.Sheets(1).Cells(Cell.Row, col) = "Codes 69 or 76 Reported w/ No applicable Bankrupcty Rptd" End If End If col = 50 Next Cell
当cells(cell.row, 8).value
确实是“”时,两者都不会注册。 不知道该怎么办。
这可能与你的Cell
variables有关。 强烈build议不要使用这个词作为variables,因为它在VB中使用。 此外,使用With
减less一点长度:
For Each cel In NewBook.Sheets(1).Range("T2:T" & lastRow) If cel.Value = 76 Or cel.Value = 69 Then MsgBox Cells(cel.Row, 8).Value With NewBook.Sheets(1) If IsEmpty(.Cells(cel.Row, 8).Value) = True Then Do Until IsEmpty(.Cells(cel.Row, col).Value) If Not .Cells(cel.Row, col).Value = "" Then col = col + 1 End If Loop .Cells(cel.Row, col) = "Codes 69 or 76 Reported w/ No applicable Bankrupcty Rptd" End If End With End If col = 50 Next cel End Sub
主要是尝试改变你的Cell
variables只是cel
(或任何你喜欢的),看看它是否工作。 With
部分只是个人喜好。
问题是与原始数据。 它来自一个CSV文件,cell.value不是“”。 它是 ” ”。 Pesky空间。