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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,215,373
Messages
6,124,544
Members
449,169
Latest member
mm424

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