如何循环遍历 K 列中的每一行,直到 A 列为空

How to loop through each row in column K until column A is empty

我是 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

这是一种方法:

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