Moving a row upwards

fluffynicesheep

Board Regular
Joined
Oct 27, 2009
Messages
69
Hi,

I currently have a macro that copies and pastes a number of rows from one workbook into a tab in another workbook.

Row 1 (Column A to PO) - is the header row
Row 2 and down (Column A to PO) is the data

This works great, and basically, other tabs in the excel document then look at the first line of data in Row 2 and inserts the required info from this row into a form ... which is then printed.

I then want to do the same thing for the data in Row 3, Row 4 .... and so on until the bottom row.


So what am I looking for?

Now the ideal thing for me to do would be to delete row 2, and then row 3 automatically moves up and the data automatically goes in, but as we know this then breaks the formula and we get a #REF error, so I'm looking for a script that does something like:


Click a button and everything in Row 3 downwards (until the final row with data in) moves up a row - so Row 3 becomes Row 2, Row 4 becomes row 3 etc .... every time you click the button whatever is in Row 2 disappears and is replaced by the line below.

This would continue until we reach the final row that contains data in it - where it won't let you move it up again , as I want to ensure that at the end of the process there is still a header row present and 1 row of data (so the formula's don't break in the other tabs!).

Not sure if this is the best way to approach this, so any help would be appreciated!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
@fluffynicesheep

I don't know you sheet names nor whether you are wanting a button in sheet or on a form.
However, something like this should work as a command button.

Code:
Private Sub CommandButton1_Click()
Dim DataSheet As Worksheet
Dim MyRange As Range
Dim LastRow As Long


Set DataSheet = Sheets("YourSheetHere")
With DataSheet
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
If LastRow = 2 Then Exit Sub
Application.ScreenUpdating = False
.Range("A2:PO" & LastRow - 1).Value = .Range("A3:PO" & LastRow).Value
.Range("A" & LastRow & ":PO" & LastRow).ClearContents
Application.ScreenUpdating = True
End With
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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