vba help - dictionary syntax

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am trying to understand one dictionary Line. Below is the line,
How to Read it. It is used to highlight duplicate values.


d(Cells(i, 1).Value) = d(Cells(i, 1).Value) + 1 ...... what this line does.?....


VBA Code:
Set d = CreateObject("Scripting.Dictionary")
  For i = 2 To 7
    d(Cells(i, 1).Value) = d(Cells(i, 1).Value) + 1 'Add comment.
  Next i


For Each itm In d.Keys
    If d(itm) = 1 Then d.Remove itm
  Next itm



Thanks
mg
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
It adds 1 to whatever value is currently stored for the Cells(i, 1).Value key, so you get an item count for each cell in the range.
 
Upvote 0
Hi Rory,

Does below lines add 1 and also key in its place.

d(Cells(i, 1).Value) = d(Cells(i, 1).Value) + 1 'Add comment.


Thanks
mg
 
Upvote 0
When you execute this part:

Code:
d(Cells(i, 1).Value) =

the key will be created if it doesn't already exist, if that's what you mean?
 
Upvote 0
Hi Rory,

Right ! key gets Created , Understood and thanks for your help on it. (y) ?


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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