Macro to compare "main row"

bb86993

New Member
Joined
May 21, 2013
Messages
23
Hello to All
Urgent help needed
1. Workbook (two sheets with numbers)
2. User manually selects range of cells (numbers in same row but different columns)
Example (main selection):
c d e f g h i j k l
1 2 3 4 5 6 7 8 9 10

3. Macro checks both sheets, compares "Main Selection" with other rows and highlights "doubles" (including "main selection")

Example rows (could be different length):
1) 2 5 7 15 27 56 47 74 85 1 10... (2,5,7,1,10 would be highlighted)
2) 1 3 8 4 22 33 55 90 10 6 7 9... (1,3,8,4,10,6,7,9 would be highlighted)

I found macro to compare ActiveCell but don't know how to modify it accordingly. Too far from programming
frown.gif

Sub HighlightCells()
ActiveSheet.UsedRange.Cells.FormatConditions.Delete
ActiveSheet.UsedRange.Cells.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:=ActiveCell
ActiveSheet.UsedRange.Cells.FormatConditions(1).Interior.ColorIndex = 4

End Sub

Thank you in advance
Your help is very appreciated
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi bb try with this
Code:
Sub HighlightCells()
    Dim cs, ca As Range
    ActiveSheet.UsedRange.Cells.Interior.ColorIndex = xlAutomatic
    For Each cs In Selection
        For Each ca In ActiveSheet.UsedRange
            If ca.Value = cs.Value Then
                ca.Cells.Interior.ColorIndex = 4
            End If
        Next ca
    Next cs
End Sub
I think it does the trick
Sergio
 
Upvote 0
12345
44377199
D4>>>>>>0match0match0
in D4=IF(ISERROR(MATCH(D8,winrange,0))*1,0,"match")

<colgroup><col span="2"><col><col span="5"></colgroup><tbody>
</tbody>
 
Upvote 0
formatting got scrambled but basically any number in lower row is checked against higher row and 0 appears if no match, match if match is found
 
Upvote 0
Hi Sergio,

Thank you for your quick reply.
Almost perfect but :(
1. Macro "erases" grid (field with numbers but grid is visible were numbers are not entered yet)
2. It doesn't include second sheet (checks just the active one)

Thank you in advance
 
Upvote 0
instead of xlautomatic use 0
like this
Code:
Sub HighlightCells()
    Dim cs, ca As Range
    ActiveSheet.UsedRange.Cells.Interior.ColorIndex = 0
    For Each cs In Selection
        For Each ca In ActiveSheet.UsedRange
            If ca.Value = cs.Value Then
                ca.Cells.Interior.ColorIndex = 4
            End If
        Next ca
    Next cs
End Sub
 
Upvote 0
Works great but checks only ActiveSheet
Could it check both of them?
Names :sheet1 & sheet2

Thanks
 
Upvote 0
Boris, Here it is, now it is checking both sheets first and second sheet
Code:
Sub HighlightCells()
    Dim cs, ca As Range
    Dim i As Integer
    For i = 1 To 2
        Sheets(i).UsedRange.Cells.Interior.ColorIndex = 0
        For Each cs In Selection
            For Each ca In Sheets(i).UsedRange
                If ca.Value = cs.Value Then
                    ca.Cells.Interior.ColorIndex = 4
                End If
            Next ca
        Next cs
    Next i
End Sub
Cheers
Sergio
 
Upvote 0

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,473
Latest member
soumyahalder4

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