Dim Cell. no "as"

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I would appreciate if you can help me understand the code below
1) What does Dim Cell mean? why "as" was omitted
2) What does "&gt" do here?
3) Is these easier implementation of similar code? Thank you.


Code:
Sub Highlight_Duplicates(Values As Range)
Dim Cell
 
For Each Cell In Values
    If WorksheetFunction.CountIf(Values, Cell.Value) > 1 Then
        Cell.Interior.ColorIndex = 6
    End If
 
Next Cell
End Sub

https://www.automateexcel.com/vba/highlight-duplicates-in-range/
 
You don't need to pass any arguments if you apply the code to the current selection:

Code:
Sub Highlight_Duplicates(Values As Range)
  Dim cell As Range

  For Each cell In ActiveSheet.RangeSelection.Cells
    '...
  Next cell
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You'll have to type it into the macro name box like this:

’Highlight_Duplicates "A1:B10"’

Note this won't work if your file is in xlsb format.
 
Upvote 0
This worked for me using the original code: Values as Range

Alt+F8

'Highlight_Duplicates(Evaluate("A1:B10"))'

M.
 
Upvote 0
Another way

G1
A1:B10

Alt+F8
'Highlight_Duplicates(Evaluate("INDIRECT(G1)"))'

M.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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