Highlight ROW (Range A:L) through VBA

ARUNCHENNAI

Board Regular
Joined
Apr 24, 2017
Messages
66
I want to highlight the duplicate row & strike the contents.
What to modify in the below code, to get the result



Code:
Dim ma As Workbook
Dim mas As Worksheet

Sub test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

'Set Master File
Set ma = ThisWorkbook
Set mas = ma.Worksheets("Master_Dept")

Dim myrng, mycel, c_rng As Range
Set myrng = mas.Range("G8:G500")
 For Each mycel In myrng
  If WorksheetFunction.CountIf(myrng, mycel.Value) > 1 Then
   mycel.Interior.ColorIndex = 3
  End If
 Next mycel

End Sub

Thanks in advance.

Arun
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Is this what you require?
Code:
Sub test()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Dim ma As Workbook
    Dim mas As Worksheet
    
    Set ma = ThisWorkbook
    Set mas = ma.Worksheets("Master_Dept")
    
    Dim myrng, mycel As Range, c_rng As Range
    Set myrng = mas.Range("G8:G500")
    For Each mycel In myrng
        If WorksheetFunction.CountIf(myrng, mycel.Value) > 1 Then
            With Rows(mycel.Row)
                .Interior.ColorIndex = 3
                .Font.Strikethrough = True
            End With
        End If
    Next mycel


    Application.ScreenUpdating = True
    Application.DisplayAlerts = True


End Sub
 
Upvote 0
@ARUNCHENNAI

Two questions:

1. Are you aware that this result could be achieved with Excel's built-in Conditional Formatting without vba?

2. Are you aware that the following line of code only declares c_rng as Range and that the other two variables will be Variant type?
Code:
Dim myrng, mycel, c_rng As Range
If you want to declare them all as Range variables, you need to specify for each one:
Code:
Dim myrng as Range, mycel as Range, c_rng As Range
 
Upvote 0
Peter_SSs. Thank you very much.

1. Yes, I'm aware of conditional formatting without vba.
2. This is new to me. I learned new information. Thank you so much.
In future, will correct my coding.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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