Simple macro question

bstratman

New Member
Joined
Sep 25, 2008
Messages
18
This should be super easy, but I haven’t found an example and can’t figure it out on my own. here’s what I have…..

I have a list of names and addresses, sorted alphabetically by state. I have an input cell, C2, where the user is to enter the State they want to look up. Then I have a button they are to click. I want to make a macro where when they click the button it selects the first row that includes the State they entered and moved down the page to that row. Everything is on the same sheet, “Registration - 243”. The range for the State to lookup is H7:H223.

Can someone please help me with what I think should be a simple lookup/matching macro? Many thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
VBA Code:
Sub FindState()
    For i = 7 To 223
        If Range("H" & i).Value = Range("C2").Value Then
            Range("H" & i).Select
            Exit For
        End If
    Next i
End Sub
 
Upvote 0
Solution
Alternative with no loop:
VBA Code:
Sub findstate()
Range("H7:H223").Find(Range("C2")).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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