Nelson78
Well-known Member
- Joined
- Sep 11, 2017
- Messages
- 526
- Office Version
- 2007
Hello everybody.
I'm tinkering with the following situation.
The starting point is the sheet "General": in column A a sequence of cities with duplicates (for example London 5 times); in column B a value for each city in column A.
The desired outcome is shown in the sheet "Detail":
for each city, all the encountered values displayed in row.
In origin the job was well done with a double cycle for ... next, but now the rows to elaborate are too much (about 20'000) for that kind of process.
So, I need something faster.
May be working with dictionary. But I need ideas to develop the code.
Thank's in advance.
I'm tinkering with the following situation.
The starting point is the sheet "General": in column A a sequence of cities with duplicates (for example London 5 times); in column B a value for each city in column A.
The desired outcome is shown in the sheet "Detail":
for each city, all the encountered values displayed in row.
In origin the job was well done with a double cycle for ... next, but now the rows to elaborate are too much (about 20'000) for that kind of process.
VBA Code:
For Each cell In Sheets("Detail").Range("A2:A" & lr)
counter = 1
For Each cell2 In Sheets("General").Range("A2:A" & lr)
If cell.Value = cell2.Value Then
cell.Offset(0, counter).Value = cell2.Offset(0, 1).Value
counter = counter + 1
End If
Next cell2
Next cell
So, I need something faster.
May be working with dictionary. But I need ideas to develop the code.
Thank's in advance.
VBA Code:
Sub elaborate ()
Dim InAry As Variant
Dim i As Long
With Sheets("General")
InAry = .Range("A2", .Range("A" & Rows.Count).End(xlUp).Offset(, 1)).Value2
End With
With CreateObject("scripting.dictionary")
....