Move selected row in table to row 3

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,689
Office Version
  1. 2007
Platform
  1. Windows
I have a table where the Headers are in row 2
My row range is A3:I3 then down the page.
My goal is to have the user select a customers name cell in column A
The user will then use the command button code to move that customers entire row to row 3

Example
Tom Jones is currently at row 10
The user will select Tom Jones name in cell A10
Click the command button.
Tom Jones should now be at row 3.
The rows after A10 should all move up as to not have row A10 with all empty cells.

Please can you advise.
Thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this
VBA Code:
Sub testing()
    Dim oLo As ListObject
    Dim oNewRow As ListRow
    Dim moveRow As Long
    
' the table to work with
Set oLo = ThisWorkbook.ActiveSheet.ListObjects("Table1")

' is selection in first column of table
If Not Intersect(Selection, oLo.ListColumns(1).DataBodyRange) Is Nothing Then
    ' the current table listrow of selection
    moveRow = Selection.Row - Selection.ListObject.Range.Row
    
    With oLo
        ' add new row as first table row
        Set oNewRow = Selection.ListObject.ListRows.Add(1)
        ' inserting the table row moved the desired selection down a row
        
        ' make new row data equal to moveRow data
        oNewRow.Range.Value = .ListRows(moveRow + 1).Range.Value
        
        ' delete moveRow from table
        .ListRows(moveRow + 1).Delete
    End With
Else
    MsgBox "Selection is not in first column in body of table"
End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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