Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2010, 12:52 PM
Zack Zack is offline Macro trouble Windows 7 Macro trouble Office 2010 (Version 14.0)
Novice
Macro trouble
 
Join Date: Oct 2010
Posts: 2
Zack is on a distinguished road
Exclamation 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!
Reply With Quote
  #2  
Old 10-02-2010, 12:40 AM
BjornS BjornS is offline Macro trouble Windows Vista Macro trouble Office 2003
Competent Performer
 
Join Date: Jan 2010
Location: Sweden
Posts: 116
BjornS is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 10-14-2010, 12:07 PM
Zack Zack is offline Macro trouble Windows 7 Macro trouble Office 2010 (Version 14.0)
Novice
Macro trouble
 
Join Date: Oct 2010
Posts: 2
Zack is on a distinguished road
Talking Thanks!

That macro worked perfectly! Thanks again BjornS!
Reply With Quote
Reply

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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft