Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi, I have tried a search but could not find what I am looking for. I have a spreadsheet and would like to be able to move rows up and down at the press of a button, so if I wanted to move row 20 to row 19, highlighting a cell in row 20 and then a click of a button would swap the two rows, I could then carry on and move the row all the way to the top if need be. Is this too much to ask? :( Any suggestions would be much appreciated. Regards Andy -- AndyR ------------------------------------------------------------------------ AndyR's Profile: http://www.excelforum.com/member.php...o&userid=15203 View this thread: http://www.excelforum.com/showthread...hreadid=394456 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Maybe a bit hasty psoting the message above, after sitting down and trying it out this simple code seems to work, can anyone see any tidying up or glaring ommissions that I have made? Cheers Andy Sub MoveDown() Selection.EntireRow.Select Selection.Cut ActiveCell.Offset(2, 0).Range("A1").Select Selection.EntireRow.Select Selection.Insert Shift:=xlDown ActiveCell.Offset(-1, 0).Range("A1").Select End Sub Sub MoveUp() Selection.EntireRow.Select Selection.Cut ActiveCell.Offset(-1, 0).Range("A1").Select Selection.EntireRow.Select Selection.Insert Shift:=xlDown End Sub -- AndyR ------------------------------------------------------------------------ AndyR's Profile: http://www.excelforum.com/member.php...o&userid=15203 View this thread: http://www.excelforum.com/showthread...hreadid=394456 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi, I'm not trained in VB so may be missing something but this seems tider
because it doesn't change the user's selection and has less lines. Also it checks for top row. Sub MoveDown() Range(ActiveCell.Row + 1 & ":" & ActiveCell.Row + 1).Cut 'Cut row below ActiveCell.EntireRow.Insert Shift:=xlDown 'Paste ActiveCell.Offset(1, 0).Select 'Move down to it End Sub Sub MoveUp() If ActiveCell.Row 1 Then Range(ActiveCell.Row & ":" & ActiveCell.Row).Cut 'Cut active row ActiveCell.Offset(-1, 0).Select 'Move up a row ActiveCell.EntireRow.Insert Shift:=xlDown 'Paste End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Moving data from multiple rows to single rows | Excel Worksheet Functions | |||
CODE 4 MOVING WITHIN A RANGE-TAB | Excel Discussion (Misc queries) | |||
Moving Code | Excel Programming | |||
Code for moving cursor one cell to the right | Excel Programming | |||
Code for moving textbox | Excel Programming |