Finding Results using VBA

MGumbrell

Registered User.
Local time
Today, 04:01
Joined
Apr 22, 2005
Messages
129
Dear All

I have a range (“numbers”) with 95 cells all containing a value (some the same)

I have a range (“results”) with 5 cells all containing user defined values (non the same)

What I would like
I have a CommandButton3 that when clicked on UserForm1 I would like any values in range (“numbers”) to bold if they match any values in range (“results”)

Regards, Matt
 
Howdy. The following is not used with a commandbutton, but could be easily adapted. This allows automatic changes in formatting whenever a change is made.

Howdy and welcome to the board.

I have done something like this, but with more options. I have a hidden worksheet (called "CFControl"), which contains a list of the items in column A, and then the color index in Col. B. Then I have this code put into the Worksheet module (not general module); right-click the worksheet tab name, and choose "View Code", then paste this into the window.

Code:
Private Sub Worksheet_Change(ByVal Target As Range) 
     ' Conditional Formatting for more than 3 conditions
    Dim rng As Range 
     ' Target is a range::therefore,it can be more than one cell
     ' For example,,someone could delete the contents of a range,
     ' or someone could enter an array..
    Set rng = Intersect(Target, Range("P2:Y72")) 
    If rng Is Nothing Then 
        Exit Sub 
    Else 
        Dim cl As Range 
        For Each cl In rng 
            On Error Resume Next 
             ' ? The preceding line doesn ?t change the cell ?s background
             ' ? color if the cell ?s value is not found in the range
             ' ? that we specified ((rngcolors).
            cl.Font.ColorIndex = _ 
            Application.WorksheetFunction.VLookup(cl.Value, _ 
            ThisWorkbook.Sheets("CFControl").Range("rngColors"), 2, False) 
            If Err.Number <> 0 Then 
                cl.Font.ColorIndex = xlNone 
            End If 
        Next cl 
    End If 
End Sub
Adjust the Target range to match your needs.

rngColors is a defined name (which would be your list of words needed for highlight, on the CFControl worksheet):

=CFControl!$A$2:$B$87

Adjust the range accordingly. You can also add other formatting options as needed.

You should be able to adapt to your needs. If not, post back.
________
Canadian recipes
 
Last edited:
Thank you Shades

I have tried to modify your code, but I am unfortunately not that clever and have not succeded.

I have attached my file. The file is for checking lottery results via a user form. I trust the workbook is self explainatory and hope that you will be able to assist further.

Regards, Matt
 

Attachments

Users who are viewing this thread

Back
Top Bottom