vba help - dictionary syntax

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
840
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
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,100
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
840
Office Version
  1. 2010
Platform
  1. Windows
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,100
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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?
 

Mallesh23

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

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


Thanks
mg
 

Watch MrExcel Video

Forum statistics

Threads
1,122,850
Messages
5,598,446
Members
414,240
Latest member
xnanx

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
Top