Selecting multiple rows of selected rows

puru

New Member
Joined
Apr 13, 2009
Messages
6
I want to select entire rows of selected multiple cells. The cells are not standard (exp. g66, f45, g74 etc. or d22,e54,d64 ect)
So, I am selecting multiple cells and i want to able to copy the entire row of those selected cells and paste on sheet2 and delete from sheet1.
 

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".
Let's see if next code can help.
Assuming the active sheet is the one with selected cells.
Code:
Option Explicit
Option Base 1    ' Set default array subscripts to 1.
Sub Copy_Selected_Rows()
Dim I As Integer
Dim MyRow()
Dim LASTROW As Long
'    Range("D10,E11,F12,C3,D4,E5").Select   '  FOR   DEBBUGING
    
    Columns("J").Insert
    ReDim MyRow(Selection.Areas.Count)
    For I = 1 To Selection.Areas.Count
        Cells(I, "J") = Selection.Areas(I).Row
    Next I
    
    Columns("J").Sort Key1:=Range("J1"), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    For I = 1 To Selection.Areas.Count
       MyRow(I) = Cells(I, "J")
    Next I
    Columns("J").Delete
    
    With Sheets("Sheet2")
        LASTROW = .Range("A" & Rows.Count).End(xlUp).Row
        For I = 1 To Selection.Areas.Count
            Rows(MyRow(I)).Copy Destination:=.Cells(LASTROW + 1, "A")
            LASTROW = LASTROW + 1
            Rows(MyRow(I)).Delete
        Next I
    End With
End Sub
 
Upvote 0
Another run just for the fun.
Code:
Sub Test()
Dim I As Integer
Dim LASTROW As Long
Dim A
    Range("C3,D8,D10,F19").Select   '  FOR   DEBBUGING
    Columns("A").Insert
    For I = 1 To Selection.Areas.Count
        Cells(Selection.Areas(I).Row, "A") = Selection.Areas(I).Row
    Next I
    With Sheets("Sheet2")
        LASTROW = .Range("A" & Rows.Count).End(xlUp).Row
        Columns("A:A").SpecialCells(xlCellTypeConstants, 23).Offset(, 1).EntireRow.Copy Destination:=.Range("A" & LASTROW)
        Columns("A:A").SpecialCells(xlCellTypeConstants, 23).EntireRow.Delete
        Columns("A").Delete Shift:=xlToLeft
        .Range(.Cells(LASTROW, "A"), .Cells(.Range("A" & Rows.Count).End(xlUp).Row, "A")).Delete Shift:=xlToLeft
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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