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.

1
  • Also you probably don't need to loop to Rows.Count. See here for how to find the last row. Commented Dec 20, 2018 at 21:14

1 Answer 1

3

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

Get rid of the Exit For to continue iterating.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.