Run Time Error '1004'

sumantaimd

New Member
Joined
Jun 5, 2012
Messages
16
Hello everybody,
I used the following macro to merge the Row

Sub Merge_Rows()

Dim LR As Long, Rw As Long
Dim delRNG As Range


LR = Range("A" & Rows.Count).End(xlUp).Row 'last row with data
Set delRNG = Range("A" & LR + 1) 'seed the delrng

For Rw = LR To 3 Step -1 'from the bottom up, merge
If Range("A" & Rw) = Range("A" & Rw - 1) Then
Range(Range("D" & Rw), Cells(Rw, Columns.Count).End(xlToLeft)).Copy _
Cells(Rw - 1, Columns.Count).End(xlToLeft).Offset(, 1)
Set delRNG = Union(delRNG, Range("A" & Rw))
End If
Next Rw

If delRNG.Rows.Count > 1 Then delRNG.EntireRow.Delete xlShiftUp
Columns.AutoFit

End Sub
to sort the following type of data


empid pay_basic pay_in_payband gdp ppay sppay sca hra tufee tpt wa
90000118280
900001 4800
900001 2640
900001 6924
900001
900001
900001
900001
900001
900001
900001
900002 9440
900002 2400
900002
900002 1320
900002
900002 2500
900002 75

it works smooth up to 70 rows at a time but in case of large number of Rows like 6000 the macro gives "RUN TIME ERROR '1004' " with following message
The information can not be pasted because the copy area and the paste area are not the same size and shape. Try one of the following
1. Click a single cell and then paste.

2. Select a range that the same size and shape and then paste.

on debugging it hi-light the following portion of the code

Range(Range("D" & Rw), Cells(Rw, Columns.Count).End(xlToLeft)).Copy _
Cells(Rw - 1, Columns.Count).End(xlToLeft).Offset(, 1)


Pls help me on that error.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I would recommend hovering over the Rw variable when you get the error to see what the value of that is at that time. Then, take a look at that row, in relation to your formula (what values are in that row and in what columns), to see if there is any weird data situation that is causing your code not to work as you planeed.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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