Cannot run vba code on another sheet

Ghesselink

New Member
Joined
Jun 7, 2018
Messages
20
Hello,

I made a button to run the following via code on another sheet (the sheet where the button is in another one called 'input'). However, when I run the code it does only seem to affect the 'Input' sheet.
I do not see what goes wrong, anyone has an idea?

Thanks in advance,


PHP:
Sub Extend()
'
' Extend Macro
'
With Worksheets("Output1")    
 Range("B2").AutoFill Destination:=Range("B2").Resize(Range("Input!G8").End(xlDown).Row - 1)  
 Range("A2").AutoFill Destination:=Range("A2").Resize(Range("Input!G8").End(xlDown).Row - 1) 
 Range("E2").AutoFill Destination:=Range("E2").Resize(Range("Input!G8").End(xlDown).Row - 1)  
 Range("F2").AutoFill Destination:=Range("F2").Resize(Range("Input!G8").End(xlDown).Row - 1)    
 Range("G2").AutoFill Destination:=Range("G2").Resize(Range("Input!G8").End(xlDown).Row - 1)   
 Range("H2").AutoFill Destination:=Range("H2").Resize(Range("Input!G8").End(xlDown).Row - 1) 
 Range("I2").AutoFill Destination:=Range("I2").Resize(Range("Input!G8").End(xlDown).Row - 1)
End With  
  
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Everywhere you have Range on the first time each line, change it to .Range.

In this situation it would also be better to change

Code:
Range("Input!G8")

to

Code:
Worksheets("Output1").Range("G8")

but not absolutely necessary.
 
Upvote 0
I tried, but it still does not work unfortunately.
The code is this now:
Got any idea?

Code:
With Worksheets("Output1")
    .Range("B2").AutoFill Destination:=.Range("B2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("A2").AutoFill Destination:=.Range("A2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("E2").AutoFill Destination:=.Range("E2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("F2").AutoFill Destination:=.Range("F2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("G2").AutoFill Destination:=.Range("G2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("H2").AutoFill Destination:=.Range("H2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
    .Range("I2").AutoFill Destination:=.Range("I2").Resize(.Range("Input!G8").End(xlDown).Row - 1)
End With
    
End Sub
 
Upvote 0
Try
Code:
Dim Rws As Long
Rws = Range("Input!G8").End(xlDown).Row - 1
With Worksheets("Output1")
    .Range("B2").AutoFill Destination:=.Range("B2").Resize(Rws)
    .Range("A2").AutoFill Destination:=.Range("A2").Resize(Rws)
    .Range("E2").AutoFill Destination:=.Range("E2").Resize(Rws)
    .Range("F2").AutoFill Destination:=.Range("F2").Resize(Rws)
    .Range("G2").AutoFill Destination:=.Range("G2").Resize(Rws)
    .Range("H2").AutoFill Destination:=.Range("H2").Resize(Rws)
    .Range("I2").AutoFill Destination:=.Range("I2").Resize(Rws)
End With
    
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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