Autofill in another workbook

Mike2

New Member
Joined
Jan 5, 2019
Messages
42
Hello,

I would like to find out how to autofill a column in another workbook.

Here is my code so far:
VBA Code:
Sub Task1 ()

    Set wb4 = Workbooks("Task1")
    Set ws4 = wb4.Sheets("Sheet1")
 
    'code lines for copy and paste from Workbook "A" to Workbook "Task1"
 
     LstRow = ws4.Range("A" & Rows.Count).End(xlUp).Row
     ws4.Range("N3").Formula = "=L3-M3"
     ws4.Range("O3").Formula = "=N3*G3"
     ws4.Range("N3:O3").AutoFill Destination:=Range("N3:O" & Lstrow)
 
 End Sub

The macro gives me a Run Time error '1004' Method 'Range' of Object'_Global' failed.
Can someone please help to explain what i am missing in my code?

Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You haven't specified the sheet on the destination range.
 
Upvote 0
Hi Fluff,
I thought I have as Range ("N3:O" & Lstrow).
The formula is on cell N3 and O3 and I wanted to fill them down to the last row of data in Workbook Task1 with Workbook A being Active.
 
Upvote 0
You are missing the ws4 from the destination, so it's looking at the activesheet, it should be
Rich (BB code):
ws4.Range("N3:O3").AutoFill Destination:=ws4.Range("N3:O" & Lstrow)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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