VBA for finding text and returning the row

OldManDemosthenes

New Member
Joined
Apr 19, 2011
Messages
38
Hi

I need to use a VBA code which will find a specific string within a worksheet and return what row that string is in.

Here's what I've tried but it does not work

Code:
Dim TestRow as Long

TestRow = Worksheets("Sheet1").Range("A1:B200"). _
[INDENT]Application.Find("Test String").Row[/INDENT]

Worksheets("Sheet1").range("C1") = TestRow

Thanks for the input!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try

Code:
Dim Found As Range
Set Found = Worksheets("Sheet1").Range("A1:B200").Find(what:="Test String", LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Worksheets("Sheet1").Range("C1").Value = Found.Row
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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