Search cells

davehill01

New Member
Joined
Jun 22, 2012
Messages
10
I need a macro to search a spreadsheet for a list of numbers.

Sinario

Every day I am sent a speadsheet of a list of part numbers (in text format) and descriptions. The first thing I have to do is check this list for certain part numbers that need updating. The list is small (Max 10 numbers) and only changes at most once a month, and I should think needs to be embedded in the macro.

I cannot use conditional formatting or VLOOKUP, because that would mean doing it every day.

Can anyone offer some help

Thanks

Dave
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Last edited:
Upvote 0
Darren

It didn't work for me.

I think it is too complicated, cutting and pasting info to other places.

All I need is a search and highlight. But I need the search criteria in the macro.

Dave
 
Upvote 0
Try this code, it'll highlight each find.

Code:
Sub Test()

    Dim rAddress As Range
    Dim wrkSht As Worksheet
    Dim x As Long
    Dim sFirstAddress As String
    
    '//Add search values here - change '0 To 2' to number of values to search for.
    Dim sSearchValue(0 To 2) As Variant
    
    sSearchValue(0) = "5468"
    sSearchValue(1) = "abcd"
    sSearchValue(2) = "QWWE"
    
    
    For Each wrkSht In Worksheets
        For x = LBound(sSearchValue) To UBound(sSearchValue)
            Set rAddress = Nothing
            Set rAddress = wrkSht.Cells.Find(What:=sSearchValue(x), _
                LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext)
            If Not rAddress Is Nothing Then
                sFirstAddress = rAddress.Address
                Do
                    With rAddress
                        .Interior.Color = 255
                        .Font.Color = -16711681
                        .Font.Bold = True
                    End With
                    Set rAddress = wrkSht.Cells.FindNext(rAddress)
                Loop While Not rAddress Is Nothing And rAddress.Address <> sFirstAddress
            End If
        Next x
    Next wrkSht

End Sub

You may want to record a macro to change the highlighting:
Code:
                    With rAddress
                        .Interior.Color = 255
                        .Font.Color = -16711681
                        .Font.Bold = True
                    End With

Currently it's red background and bold yellow text.
 
Upvote 0

Forum statistics

Threads
1,206,761
Messages
6,074,786
Members
446,088
Latest member
Koustubh12

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