macro copy a table

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
Hi All,

I have a table on sheet1 A1:B10, I'm wondering how can i use a macro to copy it to last row on sheet2?
I have this but it returns code 1004 error, application defined or object defined error

Sub test()

Sheets("Sheet1").Select
Range("A1:B10").Select
Selection.Copy

Sheets("Sheet2").Select
Cells(Rows.Count, 1).End(xlUp).Offset(6, 1).Select
ActiveSheet.Paste

End Sub

thanks for your guidance
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
VBA Code:
Option Explicit

Sub test()

Sheets("Sheet1").Select
Range("A1:B10").Select
Selection.Copy

Sheets("Sheet2").Select
Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1).Select
ActiveSheet.Paste

End Sub

Shorter and more succint

VBA Code:
Option Explicit

Sub test()

Sheets("Sheet1").Range("A1:B10").Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)

End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub test()

Sheets("Sheet1").Select
Range("A1:B10").Select
Selection.Copy

Sheets("Sheet2").Select
Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1).Select
ActiveSheet.Paste

End Sub

Shorter and more succint

VBA Code:
Option Explicit

Sub test()

Sheets("Sheet1").Range("A1:B10").Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)

End Sub

excellent alan, thanks so much
last but not least, do you think i can adjust this table row size to 30 after run this macro too?
 
Upvote 0
How about this?

VBA Code:
Option Explicit

Sub test()
'Define last row as long integer
Dim lr As Long
'Determine last row of data in column A
lr = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'Copy Range A1 to B and last row and paste to Sheet2
Sheets("Sheet1").Range("A1:B" & lr).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)

End Sub
 
Upvote 0
How about this?

VBA Code:
Option Explicit

Sub test()
'Define last row as long integer
Dim lr As Long
'Determine last row of data in column A
lr = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'Copy Range A1 to B and last row and paste to Sheet2
Sheets("Sheet1").Range("A1:B" & lr).Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)

End Sub

Nope, I've also upload my workbook here,
ps. I set row height to 50

http://kel.ddns.net/f/3b89f7beb0/?raw=1
 
Upvote 0
I misundetstood. I thought you were looking for the last row in a range. Actually, you were referring to row height. Will look and recode.

EDIT: Your link opens back to this same MrE page.
 
Upvote 0
VBA Code:
Sub test()
Sheets("Sheet1").Range("A1:B10").Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)
Sheets("Sheet2").Rows("7:16").RowHeight = 50
End Sub
 
Upvote 0
VBA Code:
Sub test()
Sheets("Sheet1").Range("A1:B10").Copy Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Rows.Offset(6, 1)
Sheets("Sheet2").Rows("7:16").RowHeight = 50
End Sub
not your fault and it's my bad presentation

however this height is only for row 7:16?
can it be flexible on any row after offset 6 more rows?
for instance, last row on 18, table height at row 24

thanks for the guidance
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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