Optimize Merge Data Code

davahill

New Member
Joined
Jan 16, 2014
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Good day,
I'm attempting to optimize a macro that was developed by Mr. Jerry Beaucaire to merge data. This takes anywhere form 2 minutes and 30 seconds to 4 minutes depending on the number of rows. My data is 67 columns and form 4,000 to 6,000 rows of information. Please see the code below. Any assistance would be greatly appreciated.


VBA Code:
Sub MergeAnyData()
'Jerry Beaucaire (4/26/2010)
'For duplicated values in column A data is sorted and merged
Dim Lastrow As Long, Rw As Long
Dim LastCol As Long, Col As Long
Dim delRNG As Range

Application.ScreenUpdating = False

Lastrow = Range("A" & Rows.Count).End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Sort table by column A
Range("A1", Cells(Lastrow, LastCol)).Sort Key1:=Range("A1"), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers
'start the delete rng
Set delRNG = Range("A" & Lastrow + 10)

'Merge data and mark rows for deletion at the end
On Error Resume Next
For Rw = Lastrow To 3 Step -1
If Range("A" & Rw) = Range("A" & Rw - 1) Then
For Col = 2 To LastCol
If Cells(Rw - 1, Col) = "" Then Cells(Rw - 1, Col) = Cells(Rw, Col)
Next Col
Set delRNG = Union(delRNG, Range("A" & Rw))
End If
Next Rw
'Delete and cleanup
delRNG.EntireRow.Delete xlShiftUp
Set delRNG = Nothing
Application.ScreenUpdating = True

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,830
Messages
6,181,225
Members
453,025
Latest member
Hannah_Pham93

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
Back
Top