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.
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.