excel macro language to Find text in selection, and then select nearby cells

sfried

New Member
Joined
Sep 24, 2013
Messages
9
I'm trying to select multiple cells (p6:p1141), find the text "amc". then select the cells to the left, the cell with amc, and the cell to the right. so if "amc" is in p28, then should select o28:q28. Then add a border on top.

That's it. I only need to find the FIRST 'amc' in the p6:p1141.


I will then copy the same code to do the same thing for column T, and column X, and several other columns.


Thanks in advance for any assistance. It is much appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This should work for you.

Code:
Sub sfried()

    Dim rFound As Range, Rng As Range
    Dim SearchTerm As Variant

    SearchTerm = "amc"    ' Change what to find here
    Set Rng = Range("P6:P1141")    ' Change Range here

    Set rFound = Rng.Find(What:=SearchTerm, After:=Rng(1, 1), _
                          LookIn:=xlValues, LookAt:=xlWhole, _
                          SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                          MatchCase:=False, SearchFormat:=False)

    If Not rFound Is Nothing Then
        rFound.Offset(, -1).Resize(, 3).Borders(xlEdgeTop).LineStyle = xlContinuous
    Else
        MsgBox SearchTerm & " not found."
    End If

End Sub


Hope this helps.
WD
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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