Stuart Duncan
Stuart Duncan

Reputation: 3

Loop through all values

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.

Upvotes: 0

Views: 62

Answers (1)

BigBen
BigBen

Reputation: 50008

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

Get rid of the Exit For to continue iterating.

Upvotes: 3

Related Questions