LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Query for Macro

Each unique Entries and their corresponding values should get concatenate with uniqueness,Attached macro working correctly but not efficient,I need some suggestion to avoid the Multiple if checks and , Is it possible to create dictionary objects with loops. I want to automate this too.


Sub Working_With_Dic()

Application.ScreenUpdating = False

Set Dc = CreateObject("Scripting.dictionary")
Set Dc1 = CreateObject("Scripting.dictionary")
Set Dc2 = CreateObject("Scripting.dictionary")
Set Dc3 = CreateObject("Scripting.dictionary")

Dc.RemoveAll
Dc1.RemoveAll
Dc2.RemoveAll
Dc3.RemoveAll


For i = 1 To 1085
If Not Dc.Exists(Cells(i, 1).Value) Then
Dc.Add Cells(i, 1).Value, Cells(i, 2).Value
Dc1.Add Cells(i, 1).Value, Cells(i, 3).Value
Dc2.Add Cells(i, 1).Value, Cells(i, 4).Value
Dc3.Add Cells(i, 1).Value, Cells(i, 5).Value

Else
If InStr(1, Dc.Item(Cells(i, 1).Value), Cells(i, 2).Value, vbBinaryCompare) = 0 Then
Dc.Item(Cells(i, 1).Value) = Dc.Item(Cells(i, 1).Value) & "+" & Cells(i, 2).Value
End If

If InStr(1, Dc1.Item(Cells(i, 1).Value), Cells(i, 3).Value, vbBinaryCompare) = 0 Then
Dc1.Item(Cells(i, 1).Value) = Dc1.Item(Cells(i, 1).Value) & "+" & Cells(i, 3).Value
End If

If InStr(1, Dc2.Item(Cells(i, 1).Value), Cells(i, 4).Value, vbBinaryCompare) = 0 Then
Dc2.Item(Cells(i, 1).Value) = Dc2.Item(Cells(i, 1).Value) & "+" & Cells(i, 4).Value
End If

If InStr(1, Dc3.Item(Cells(i, 1).Value), Cells(i, 5).Value, vbBinaryCompare) = 0 Then
Dc3.Item(Cells(i, 1).Value) = Dc.Item(Cells(i, 1).Value) & "+" & Cells(i, 5).Value
End If

End If
Next

i = 1
For Each k In Dc.keys
With Sheets("Sheet2")
.Cells(i, 1) = k
.Cells(i, 2) = Dc.Item(k)
.Cells(i, 3) = Dc1.Item(k)
.Cells(i, 4) = Dc2.Item(k)
.Cells(i, 5) = Dc3.Item(k)
End With
i = i + 1
Next
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Query rmsmith Excel Discussion (Misc queries) 1 December 15th 09 06:32 PM
Web query: Want to pause macro while Web query completes refreshin Ellis Excel Programming 4 August 6th 07 04:04 AM
another macro query - deleting a worksheet within a query DavidHawes Excel Discussion (Misc queries) 2 February 26th 07 10:05 AM
Macro Query Greg B[_8_] Excel Programming 3 April 2nd 06 12:56 PM
Query Macro Steve Excel Programming 7 May 19th 05 05:10 AM


All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"