Hi dmreno
A while I'd think...let me know how it goes.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
It is at 3 hours now and still running. is it vastly different from what the first code was doing? That code took less than 30 minutes to run through the 22,000 rows. Tha is why I am asking the question.
Hi dmreno
Actually the code is significantly less complex with far fewer IO's. I'm assuming you've run the procedure on a COPY of the real file???
Assuming you did, kill the procedure (hold down the escape key...it may take a bit...make a note of the line of code where the procedure break point is) and let me know that line.
Assuming you didn't, I have to assume you have a BACKUP???
Let me play with it for a bit...I can look at eliminating the Copy/Paste stuff...that may speed it up.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi David
I should of asked and didn't...which file ALWAYS has the fewer records...OldMel or NewMel?
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
It locked up but did not see your post till now. I am going to run it again, right now.
here is the line of code that was highlighted. the current situation has the newmel file with more rows than the oldmel but not sure if that will always be the case.
Application.CutCopyMode = False
Hi David
See if this code works any betterOption Explicit Sub test() Dim lr1 As Long Dim lr2 As Long Dim ws1 As Worksheet Dim ws2 As Worksheet Dim rng1 As Range Dim rng2 As Range Dim cel2 As Range Dim FindString As String Application.ScreenUpdating = False Set ws1 = Sheet1 'NewMel Set ws2 = Sheet2 'OldMel lr1 = ws1.Range("A" & Rows.Count).End(xlUp).Row lr2 = ws2.Range("A" & Rows.Count).End(xlUp).Row Set rng2 = ws2.Range("A2:A" & lr2) 'With each value in OldMel Column A, find it in 'NewMel Column A; if found, replace NewMel row with OldMel row; 'if not found do nothing For Each cel2 In rng2 'OldMel FindString = cel2.Value If Trim(FindString) <> "" Then With ws1.Range("A2:A" & lr1) Set rng1 = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not rng1 Is Nothing Then ' Application.Goto rng1, True ' ws2.Range("A" & cel2.Row).EntireRow.Copy ' ws1.Range("A" & rng1.Row).PasteSpecial ws1.Range("A" & rng1.Row).Resize(1, 21).Value = ws2.Range("A" & cel2.Row).Resize(1, 21).Value ' Application.CutCopyMode = False End If End With End If Next cel2 Application.ScreenUpdating = True End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi David
Then try this code...let me know what works...what doesn't
Option Explicit Sub test() Dim lr1 As Long Dim lr2 As Long Dim ws1 As Worksheet Dim ws2 As Worksheet Dim rng1 As Range Dim rng2 As Range Dim cel2 As Range Dim FindString As String Dim xlCalc As XlCalculation On Error GoTo ExitPoint With Application xlCalc = .Calculation .Calculation = xlCalculationManual .EnableEvents = False .ScreenUpdating = False End With Set ws1 = Sheet1 'NewMel Set ws2 = Sheet2 'OldMel lr1 = ws1.Range("A" & Rows.Count).End(xlUp).Row lr2 = ws2.Range("A" & Rows.Count).End(xlUp).Row Set rng2 = ws2.Range("A2:A" & lr2) 'With each value in OldMel Column A, find it in 'NewMel Column A; if found, replace NewMel row with OldMel row; 'if not found do nothing For Each cel2 In rng2 'OldMel FindString = cel2.Value If Trim(FindString) <> "" Then With ws1.Range("A2:A" & lr1) Set rng1 = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not rng1 Is Nothing Then ws1.Range("A" & rng1.Row).Resize(1, 21).Value = ws2.Range("A" & cel2.Row).Resize(1, 21).Value End If End With End If Next cel2 ExitPoint: With Application .Calculation = xlCalc .EnableEvents = True .ScreenUpdating = True End With End Sub
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
It appears that both codes work and provide same results. What is the difference in the two? Is one faster running than the other? I will test on a backup version of the 22k row file and let you know.
Hi David...the two are the same code and do the same things the same way. The second version turns off calculation so I would expect it to be at least marginally faster.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hey John,
I finally was able to get it to run on the the main file. Both worked and it took only 5 minutes to run on the 22 K row of information. We are still not sure why they were hangin up on the older files I had, but I did creat a whole new one and it ran perfectly. Thanks again for all your help..
Once again you came through with excellent code that works flawlessly and I greatly appreciate it very much.
David
Last edited by dmreno; 01-31-2012 at 07:54 AM. Reason: to add thanks to jaslake for his help
You're welcome.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks