Any faster version of the same code to handle 5000+ records
Closed
upan275
-
Dec 15, 2016 at 01:57 AM
Smallman1 Posts 5 Registration date Sunday December 18, 2016 Status Member Last seen December 21, 2016 - Dec 21, 2016 at 07:28 PM
Smallman1 Posts 5 Registration date Sunday December 18, 2016 Status Member Last seen December 21, 2016 - Dec 21, 2016 at 07:28 PM
Related:
- Any faster version of the same code to handle 5000+ records
- Download windows 10 64-bit full version free - Download - Windows
- The grim reaper rus apk english version - Download - Adult games
- Battery reset code - Guide
- Granny pc version download for android - Download - Horror
- Euro truck simulator 2 download free full version pc - Download - Simulation
3 responses
yg_be
Posts
23416
Registration date
Sunday June 8, 2008
Status
Contributor
Last seen
January 3, 2025
5
Dec 15, 2016 at 02:29 PM
Dec 15, 2016 at 02:29 PM
Highlighting the matched cells is easy. Simply add this in the if section, after the copy:
Improving the algorithm will require some VBA skills, and some time to use those skills. Are you prepared to spend time to learn that? If yes, I can provide some guidance.
The general idea would be to do the matching on sorted values. This is what you would do in real life, if you had to match two large sets of values, such as two sets of 1000 cards with a word on each card.
cell.Interior.Color = 65535 Sheets(2).Cells(x, "A").Interior.Color = 65535
Improving the algorithm will require some VBA skills, and some time to use those skills. Are you prepared to spend time to learn that? If yes, I can provide some guidance.
The general idea would be to do the matching on sorted values. This is what you would do in real life, if you had to match two large sets of values, such as two sets of 1000 cards with a word on each card.
yg_be
Posts
23416
Registration date
Sunday June 8, 2008
Status
Contributor
Last seen
January 3, 2025
5
Dec 18, 2016 at 05:59 AM
Dec 18, 2016 at 05:59 AM
I believe
Loop Until IsEmpty(Sheets(1).Cells(x, "C"))should be
Loop Until IsEmpty(Sheets(2).Cells(x, "A"))
Smallman1
Posts
5
Registration date
Sunday December 18, 2016
Status
Member
Last seen
December 21, 2016
Updated by Smallman1 on 18/12/16 at 06:12 PM
Updated by Smallman1 on 18/12/16 at 06:12 PM
Hi
I had a friend ask me to solve the above for him, he was asking out of interest alone and I thought I would share the solution with the community. I wrote a blog post about it here where you can see a working version of the file.
https://www.thesmallman.com/blog/2016/12/16/compare-two-lists-on-different-sheets-and-ouput-matches
I had written similar blog posts in the past but this was specific to this particular thread.
The code is as follows and processes about 4.5K rows in less than half a second.
Take care
Smallman
I had a friend ask me to solve the above for him, he was asking out of interest alone and I thought I would share the solution with the community. I wrote a blog post about it here where you can see a working version of the file.
https://www.thesmallman.com/blog/2016/12/16/compare-two-lists-on-different-sheets-and-ouput-matches
I had written similar blog posts in the past but this was specific to this particular thread.
The code is as follows and processes about 4.5K rows in less than half a second.
Option Explicit
Sub CompareSolve()
Dim i As Long
Dim j As Long
Dim ar As Variant
ar = Sheet2.Cells(1, 3).CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(ar, 1)
.Item(ar(i, 1)) = Empty
Next
ar = Sheet1.Cells(1).CurrentRegion.Value
n = 1
For i = 2 To UBound(ar, 1)
If .exists(ar(i, 1)) Then
n = n + 1
For j = 1 To UBound(ar, 2)
n = n + 1
ar(n, j) = ar(i, j)
Next j
End If
Next i
End With
Sheet3.Cells(1).Resize(n, UBound(ar, 2)).Value = ar
End Sub
Take care
Smallman
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
262
>
Smallman1
Posts
5
Registration date
Sunday December 18, 2016
Status
Member
Last seen
December 21, 2016
Dec 18, 2016 at 10:19 PM
Dec 18, 2016 at 10:19 PM
@Smallman.
Thanks for the snippet. The code that you supplied is "weapons grade" stuff. Super efficient, super fast. The OP should have a massive smile on his/her face by now.
Cheerio,
vcoolio.
Thanks for the snippet. The code that you supplied is "weapons grade" stuff. Super efficient, super fast. The OP should have a massive smile on his/her face by now.
Cheerio,
vcoolio.
Smallman1
Posts
5
Registration date
Sunday December 18, 2016
Status
Member
Last seen
December 21, 2016
>
vcoolio
Posts
1411
Registration date
Thursday July 24, 2014
Status
Moderator
Last seen
September 6, 2024
Updated by vcoolio on 19/12/16 at 04:10 PM
Updated by vcoolio on 19/12/16 at 04:10 PM
LOL - we will see, mostly people just take and leave in my experience. Have a good Christmas VC!!!
upan275
Posts
4
Registration date
Thursday December 15, 2016
Status
Member
Last seen
December 21, 2016
Dec 19, 2016 at 07:35 AM
Dec 19, 2016 at 07:35 AM
Hey Smallman1, you are same as your code...too fast to Judge people....Merry Christmas...Thanks for your help....Thanks all....
yg_be
Posts
23416
Registration date
Sunday June 8, 2008
Status
Contributor
Last seen
January 3, 2025
5
>
Smallman1
Posts
5
Registration date
Sunday December 18, 2016
Status
Member
Last seen
December 21, 2016
Dec 19, 2016 at 03:04 PM
Dec 19, 2016 at 03:04 PM
@Smallman, what's the purpose of incrementing n in the "for j" loop?
upan275
Posts
4
Registration date
Thursday December 15, 2016
Status
Member
Last seen
December 21, 2016
Dec 21, 2016 at 01:39 AM
Dec 21, 2016 at 01:39 AM
Hello All,
During Trials to customize code as per my requirement. (I.E.column selection as Msg Box for user to select) I notice a weirdo problem.
When i select a data in Sht2 next to Col C Outcome is always Headers only. As soon as I make blank columns both side of Column C,I get desired Result.
Fyi,I am using SmallMan1’s Template. Thanks for the wonderful site mate!
During Trials to customize code as per my requirement. (I.E.column selection as Msg Box for user to select) I notice a weirdo problem.
When i select a data in Sht2 next to Col C Outcome is always Headers only. As soon as I make blank columns both side of Column C,I get desired Result.
Fyi,I am using SmallMan1’s Template. Thanks for the wonderful site mate!
Option Explicit
Sub DicSolve() 'Excel VBA find duplicates with the scripting dictionary.
Dim ar As Variant
Dim i As Long
Dim j As Long
Dim n As Long
ar = Sheet2.Cells(1, 3).CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(ar, 1)
.Item(ar(i, 1)) = Empty
Next
ar = Sheet1.Cells(1).CurrentRegion.Value
n = 1
For i = 2 To UBound(ar, 1)
If .exists(ar(i, 1)) Then
n = n + 1
For j = 1 To UBound(ar, 2)
ar(n, j) = ar(i, j)
Next
End If
Next
End With
Sheet3.Cells(10, 1).Resize(n, UBound(ar, 2)).Value = ar
End Sub
Smallman1
Posts
5
Registration date
Sunday December 18, 2016
Status
Member
Last seen
December 21, 2016
Dec 21, 2016 at 07:28 PM
Dec 21, 2016 at 07:28 PM
Hi Upan275
Thanks for the reply. Mmmm I can't seem to replicate your issue - no bother - if you send me your file with some instructions on what you want to achieve I will customise it for you - it is Christmas after all.
My email is MarcusSmallATTLESthesmallman.com Obvo replace ATTLES with the @ symbol : )
Take care
Smallman
Thanks for the reply. Mmmm I can't seem to replicate your issue - no bother - if you send me your file with some instructions on what you want to achieve I will customise it for you - it is Christmas after all.
My email is MarcusSmallATTLESthesmallman.com Obvo replace ATTLES with the @ symbol : )
Take care
Smallman
Dec 18, 2016 at 03:23 AM
Thanks for the highlighting code.
Yes I do.Please shoot at me...I'ii try my level best....
Cannot understand what do you exactly mean by Sorting Algorithm though....My data is 5000+ records and majority of them are alphanumerical & sorted in ascending order in excel..!
Updated by yg_be on 18/12/16 at 05:48 AM
Then you can "easily" do something much faster; I am preparing suggestions.
Are your values unique, or can you have several identical values in the columns you compare?
Dec 19, 2016 at 07:38 AM
Updated by yg_be on 18/12/16 at 06:32 AM