仅当我的表在AJ列上完成时,以下代码才有效。我的表可以在AJ列之前完成。我该如何修改代码,以便当我的表在任何列中完成时可以工作?
谢谢。
Dim row As Long, Column As Long
With ThisWorkbook.Worksheets("Data")
LastRow0 = .Cells(.Rows.Count, "AI").End(xlUp).row
For row = 8 To LastRow0 Step 3
For Column = 5 To 35
If Cells(row, Column).Value = "" Then
Cells(row, Column).Value = 0
End If
Next Column
Next row
End With
答案 0 :(得分:2)
您已经找到了lastRow,现在需要lastColumn。
Dim row As Long, Column As Long
With ThisWorkbook.Worksheets("Data")
LastRow0 = .Cells(.Rows.Count, "AI").End(xlUp).row
.UsedRange
LastCol0 = .UsedRange.Columns(.UsedRange.Columns.Count).Column
For row = 8 To LastRow0 Step 3
For Column = 5 To LastCol0
If Cells(row, Column).Value = "" Then
Cells(row, Column).Value = 0
End If
Next Column
Next row
End With