I'm new to VBA and am trying to figure out how to do the following:
I have no trouble getting the code to look at one particular row, but I can't figure out how to get it to loop through all rows where A is not empty.
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
Here's one way to do it:
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