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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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