dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have 5 worksheets, 4 of which---Sheet 1, 2, 3, and 4 contain tables.
The fifth worksheet is called "MACRO" and I'm using it for a user interface, so I need to avoid running the macro in this worksheet.
What I want to do is put a formula into cell AF16 of worksheets 1 to 4, and autofill down through the range ("AF16:AF214"). Each time I am given worksheets 1 to 4, they come with different names, hence I've tried to get my VBA code to run on all worksheets except ws.name ("MACRO").
I have this VBA code.
It does the job in the ok in Sheet 1, then enters the correct formula into AF16 of Sheet 2, but then the following error stops the job: Run-time error '1004': AutoFill method of Range class failed.
Would anyone be willing to show me how to modify the code so it inserts the formula into AF16, fills down to AF214, and then cycle through to the next worksheet and repeats?
Kind regards,
Doug
I have 5 worksheets, 4 of which---Sheet 1, 2, 3, and 4 contain tables.
The fifth worksheet is called "MACRO" and I'm using it for a user interface, so I need to avoid running the macro in this worksheet.
What I want to do is put a formula into cell AF16 of worksheets 1 to 4, and autofill down through the range ("AF16:AF214"). Each time I am given worksheets 1 to 4, they come with different names, hence I've tried to get my VBA code to run on all worksheets except ws.name ("MACRO").
I have this VBA code.
Code:
Sub AutoFillDownAF15()
Dim xWs As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> "MACRO" Then
xWs.Range("AF16").FormulaR1C1 = "=IF(RC[-31]="""","""",R15C32)"
xWs.Range("AF16").AutoFill Destination:=Range("AF16:AF214")
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
It does the job in the ok in Sheet 1, then enters the correct formula into AF16 of Sheet 2, but then the following error stops the job: Run-time error '1004': AutoFill method of Range class failed.
Would anyone be willing to show me how to modify the code so it inserts the formula into AF16, fills down to AF214, and then cycle through to the next worksheet and repeats?
Kind regards,
Doug
Last edited: