How to change vb script to use active row

mattkirby

New Member
Joined
Jan 5, 2016
Messages
11
Hi

I've got a macro that searches column A for a specific text then moves across to column D to copy the data in the cell. The vb script looks like this:

Code:
Range("D22").Select

However, the search might not always find the specific text in row 22 but will always copy the data from column D. Is there a way to change the script to use the current/active row after the search instead of using row 22?

Thanks
Matt
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This would do that:

Code:
Dim str_find As String, c As Range

str_find = "whatever"
Set c = Columns("A").Find(What:=str_find, LookAt:=xlWhole)
If Not c Is Nothing Then c.Offset(0, 3).Copy
 
Upvote 0
Matt

Perhaps something like this.
Code:
strSearchTerm = "Something"

Res = Application.Match(strSearchTerm,  Columns(1), 0)

If Not IsError(Res) Then
    Range("D" & Res).Copy
End if
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,381
Members
448,888
Latest member
Arle8907

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