Forum Discussion
csigman
Apr 08, 2022Copper Contributor
Do Until Loop Code
Hello, I'm trying to create a Do Until code in VBA that will populate a certain value in column A until a criteria is met in column B, after which it will populate a second value. I think this s...
- Apr 08, 2022
For example:
Sub FillA() Dim r As Long Dim m As Long Dim s As String Application.ScreenUpdating = False s = Range("F2").Value m = Range("B" & Rows.Count).End(xlUp).Row For r = 6 To m If Range("B" & r).Value = "Entity_ID" Then s = Range("F3").Value End If Range("A" & r).Value = s Next r Application.ScreenUpdating = True End SubYou could also use a formula. In A6:
=IF(COUNTIF(B$6:B6,"Entity_ID"),$F$3,$F$2)
Double-click the fill handle of A6 to fill down.
HansVogelaar
Apr 08, 2022MVP
For example:
Sub FillA()
Dim r As Long
Dim m As Long
Dim s As String
Application.ScreenUpdating = False
s = Range("F2").Value
m = Range("B" & Rows.Count).End(xlUp).Row
For r = 6 To m
If Range("B" & r).Value = "Entity_ID" Then
s = Range("F3").Value
End If
Range("A" & r).Value = s
Next r
Application.ScreenUpdating = True
End Sub
You could also use a formula. In A6:
=IF(COUNTIF(B$6:B6,"Entity_ID"),$F$3,$F$2)
Double-click the fill handle of A6 to fill down.
csigman
Apr 09, 2022Copper Contributor
Thank you!