Won't Paste to Next Blank Row?

msgtgumby

New Member
Joined
Jan 19, 2017
Messages
10
Kind of new to this. I'm trying to copy range A:H from sheet 17 of one workbook to sheet 1 of another workbook (both already open). I got it to work, but it pasted to the top of sheet 1, I need it to paste to the next available blank row. I'm new at this and can't really figure out how to set my range to that? I tried a few things I found throughout various sites and forms, but couldn't get it to work. What's below is the last thing I've tried, still pops an error.

Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook

Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")

Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

End Sub

Thanks for any help you can give me.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
try,

Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook
Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")
Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub
 
Upvote 0
Kind of new to this. I'm trying to copy range A:H from sheet 17 of one workbook to sheet 1 of another workbook (both already open). I got it to work, but it pasted to the top of sheet 1, I need it to paste to the next available blank row. I'm new at this and can't really figure out how to set my range to that? I tried a few things I found throughout various sites and forms, but couldn't get it to work. What's below is the last thing I've tried, still pops an error.

Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook

Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")

Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & Rows.Count).Offset(1, 0)

End Sub

Thanks for any help you can give me.

If column A is blank, then your last row with data will be row 1, even though you have data in other columns, because you are using column A as the criteria column. To avoid that quirk, try this.
Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook, lr As Long
lr = wb2.sheets("Invoice1").Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")
Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & lr).Offset(1, 0)
End Sub
 
Last edited:
Upvote 0
try,

Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook
Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")
Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End Sub

This now copies it to row 1055 for some reason? The row isn't blank, the first available blank row is 17790.
 
Upvote 0
If column A is blank, then your last row with data will be row 1, even though you have data in other columns, because you are using column A as the criteria column. To avoid that quirk, try this.
Code:
Sub CopyData()
Dim Wb1 As Workbook, wb2 As Workbook, lr As Long
lr = wb2.sheets("Invoice1").Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set Wb1 = ThisWorkbook
Set wb2 = Workbooks("invoiceTEST.xls")
Wb1.Sheets(17).Range("A:H").CurrentRegion.Copy wb2.Sheets("Invoice1").Range("A" & lr).Offset(1, 0)
End Sub

A isn't blank, I had to make sure of it, a few other things I run on the sheet required A to have data.
 
Upvote 0
what does the below give you?

Code:
sub test()
dim lr as long
lr = Workbooks("invoiceTEST.xls").Sheets("Invoice1").Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
msgbox lr
End sub
 
Upvote 0
When I run it in invoiceTEST.xls it says 0, when I run it from my other workbook it says 110. I have no clue what's going on here, it's 17k+ rows of data so I don't understand.
 
Upvote 0
sorry should be below

Code:
sub test()
dim lr as long
lr = Workbooks("invoiceTEST.xls").Sheets("Invoice1").Range("A" & Rows.Count).End(xlUp).Row
msgbox lr
End sub
 
Upvote 0

Forum statistics

Threads
1,216,729
Messages
6,132,384
Members
449,725
Latest member
Enero1

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