Repeat Code for ALL Occurrences

brolsen

New Member
Joined
Aug 11, 2011
Messages
14
I hope someone can help me with this, it might not be that complicated. I have a code that looks for a value in a cell and then finds that value in a range, once the value is located it will place a value in another cell offset by 3 columns.

Code:
Sub Mark()    Sheets("Sheet1").Select
    Dim LR As Long, i As Long
    With Sheets("Sheet1")
        LR = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 1 To LR
            With .Range("A" & i)
                If .Value = Range("H10").Value Then
                    .Offset(0, 3).Select
                    Selection.Value = "Y"
                   Exit Sub
                End If
            End With
        Next i
    End With
End Sub

So for example: If "Dog" is in cell H10, then the code looks for "Dog" in column A, when it finds a cell that has Dog in it, it will place "Y" the same row but offset 3 columns (column D).
The code works PERFECT for what I need it to do with one exception... unfortunately if "Dog" appears in column A more than once, the code will only work for the first occurrence and not the second.

Does anyone know how to modify this code so it will continue until ALL occurrences of Dog in Column A have "Y" in column D on the same row?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
brolsen,

If I understand your macro code correctly, it would appear that the following line of code is stopping the macro after the first found cell.

Rich (BB code):
Exit Sub

Try removing the line of code in a copy of your workbook for testing.
 
Upvote 0
Well... THAT'S EMBARRASSING!
LOL that totally worked... and now I go and hide in my shame.
Thanks hiker95! I dunno why I didn't try that!
 
Upvote 0
brolsen,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top