0

I want to loop through a column and modify the adjacent column if a certain value is found.

I have it semi-working. It only modifies one value rather than all instances.

Sub PopulateField()

    For i = 2 To Rows.Count

        If Cells(i, 2).Value = "25 December 2018" Then
            Cells(i, 3).Value = "Holiday"
            Exit For
        End If
    Next i

End Sub

I would like it to be:

25 December 2018    Holiday
25 December 2018    Holiday
25 December 2018    Holiday
25 December 2018    Holiday
25 December 2018    Holiday

But currently it's only:

25 December 2018    Holiday
25 December 2018    
25 December 2018    
25 December 2018    
25 December 2018    

It doesn't seem to be iterating over all values.

Community
  • 1
  • 1
  • Also you probably don't need to loop to `Rows.Count`. See [here](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba) for how to find the last row. – BigBen Dec 20 '18 at 21:14

1 Answers1

3

You're exiting the loop after the first instance of 25 December 2018.

Get rid of the Exit For to continue iterating.

BigBen
  • 46,229
  • 7
  • 24
  • 40