#1
|
|||
|
|||
Macro trouble
Hey all this is my first time here, so I hope I can get some help from all you office Guru's.
Im working with a spreadsheet in Excel 2010 and have been tasked to create 3 macros. 1 macro to delete an entire row at once with a keystroke, which is done. And also 2 macros to move a row of data up 1 line or down 1 line and shift the rows around it, without losing any data. I was able to create a macro to move a row of data up 1 lines and have the line above it shift down, basically swapping the two lines. Here's my "Move Line Up" code: Sub Moveup() ' ' Moveup Macro ' ' Keyboard Shortcut: Ctrl+u ' ActiveCell.Rows("1:1").EntireRow.Select Selection.Cut ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select Selection.Insert Shift:=xlDown End Sub This method does work for moving a line. HOWEVER when I try creating one to move a row DOWN, all that happens is the selection box moves down, not the data itself. Sub MoveDown() ' ' MoveDown Macro ' ' Keyboard Shortcut: Ctrl+a ' ActiveCell.Rows("1:1").EntireRow.Select Selection.Cut ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select Selection.Insert Shift:=xlDown End Sub BOTTOM LINE: Does anyone have any ideas here? I need to move a single row of data down 1 line and have the row below it move up. HELP! |
#2
|
|||
|
|||
Hi,
try this. Works for me. Note: the second last row: "ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select" is only to get the moved row marked. Kind regards Bjorn Sub MoveDown() ' ' MoveDown Macro ' ' Keyboard Shortcut: Ctrl+a ' ActiveCell.Rows("1:1").EntireRow.Select Selection.Cut ActiveCell.Offset(2, 0).Rows("1:1").EntireRow.Select Selection.Insert Shift:=xlDown ActiveCell.Offset(-1, 0).Rows("1:1").EntireRow.Select End Sub |
#3
|
|||
|
|||
Thanks!
That macro worked perfectly! Thanks again BjornS!
|
Tags |
excel 2010, macro |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Trouble Inserting Cells | ebolton | Excel | 4 | 07-21-2010 11:39 AM |
Having trouble with layout master slides | shs | PowerPoint | 0 | 04-21-2010 09:00 AM |
Having trouble with keywords in Outlook Rule | mfarring | Outlook | 0 | 02-03-2010 08:17 AM |
Trouble with project editing!!! | Guidd | Project | 0 | 07-10-2007 09:46 PM |
Trouble updating a form | TomCaesar | Outlook | 0 | 11-29-2006 10:52 AM |