Copying data

Brighton

New Member
Joined
Aug 20, 2009
Messages
9
I've been trying for a while to write a code that will copy the data between two workbooks (lets say A and B) but will only copy columns A2:T2 and then down the used range. I am unsure as how to state that in the code.

Does anyone have any examples of code they got to work for copying between workbooks in Excel?

This is something I have to run once a month for monthly reports.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to MrExcel board....

here is a sample of copying between two sheets

Code:
Sub Sheet1_2()
Dim LR As Long, ALR As Long
Dim wb2 As Variant
LR = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1
ALR = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb2 = "Sheet1"
Sheets("Sheet2").Range("A1:Z" & LR).Copy Destination:=Sheets(wb2).Range("A" & ALR)
End Sub

then change the ranges to your area
 
Upvote 0
I have this:

Sub Sheet1_2()
Dim LR As Long, ALR As Long
Dim wb2 As Variant
LR = Sheets("BSanford").Cells(Rows.Count, 1).End(xlUp).Row + 1
ALR = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb2 = "Master"
Sheets("BSandford").Range("A2:T2" & LR).Copy Destination:=Sheets(wb2).Range("A" & ALR)
End Sub

and I keep getting a runtime error 9 that tells me the script is out of range. Any other ideas?
 
Upvote 0
Try

Code:
Sheets("BSandford").Range("A2:T" & LR).Copy Destination:=Sheets(wb2).Range("A" & ALR)
 
Upvote 0
I did try that, it gave me the same error.
I'm probably not realizing something very simple. Thanks for trying to help so far though.
 
Upvote 0
What is the name of the sheet - red or blue

Rich (BB code):
Sub Sheet1_2()
Dim LR As Long, ALR As Long
Dim wb2 As Variant
LR = Sheets("BSanford").Cells(Rows.Count, 1).End(xlUp).Row + 1
ALR = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row + 1
wb2 = "Master"
Sheets("BSandford").Range("A2:T" & LR).Copy Destination:=Sheets(wb2).Range("A" & ALR)
End Sub
 
Upvote 0
also notice the other change that Peter shows where you had a2:t2 you don't want the 2 after the T.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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