Macro that pastes at variable row

CBurrows

New Member
Joined
Mar 27, 2013
Messages
1
Hey Forum,

So I have two worksheets that I need a macro to copy all contents from both worksheet and paste it to one "Aggregate" worksheet.
The kicker is that Worksheet1 has to go first, and the number or rows with data varies each time the data is collected.
So how do I create a macro that will paste the data from Worksheet2 the row below the last row in worksheet1.

Example:
Worksheet 1 has 'x' rows with contents, the first row from Worksheet2 needs to be paisted at row:'x+1'

Thanks for anyhelp you can give!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Hi and welcome to the board.
There is more than one way to determine the next 'available' row in your sheet.
The first example finds the next row, based on the length of data in column A. (This can be done using any column you like by changing the "A" to the column of choice.)
Code:
Sub FindNextRowInColumnA()
Dim LstRw As Long
LstRw = Cells(Rows.Count, "A").End(xlUp).Row

MsgBox "The next available row in column A is row " & LstRw + 1

End Sub
This second example will find the first completely blank row. As in you have some columns with more data in them than other columns and you don't necessarily know which column is longest.
Code:
Sub FindNextAvailableBlankRow()
Dim LstRw As Long
LstRw = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

MsgBox "The first completely blank row is row " & LstRw + 1

End Sub

There are of course more ways than this, but using either of these should do what you've asked.

Hope it helps.
 
Upvote 0

patel45

Well-known Member
Joined
Jul 15, 2012
Messages
1,953
Code:
sub a()
LastRow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
Sheets(2).UsedRange.copy Sheets(1).cells(LastRow + 1,1)
end sub
 
Upvote 0

Forum statistics

Threads
1,195,631
Messages
6,010,783
Members
441,569
Latest member
PeggyLee

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
Top