我是VBA的新手,正在尝试弄清楚如何做:
我可以很轻松地让代码查看某一特定行,但是我不知道如何使它遍历A不为空的所有行。
Sub FillEmptyCells()
Dim Lastrow As Long
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Do Until IsEmpty("A1:A")
If IsEmpty(Range("K1").Value) = True Then
Range("K1") = Range("E1")
End If
If IsEmpty(Range("K1").Value) = True Then
Range("K1") = Range("G1")
End If
If IsEmpty(Range("K1").Value) = True Then
Range("K1") = Range("I1")
End If
Loop
End Sub
答案 0 :(得分:1)
这里是一种方法:
Sub tgr()
Dim ws As Worksheet
Set ws = ActiveWorkbook.ActiveSheet
With ws.Range("K1:K" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row)
.Formula = "=IF(E" & .Row & "<>"""",E" & .Row & ",IF(G" & .Row & "<>"""",G" & .Row & ",I" & .Row & "))"
.Value = .Value
End With
End Sub