Why am I getting an object required error?

nidenikolev

New Member
Joined
Jun 6, 2018
Messages
20
Working on a script and this line of code keeps coming up with an object required error : .AutoFill Destination:=.Range("AT2:AT" & lastrow)

I also have it labeled towards the bottom of the script, can anyone help out?


Code:
Sub Update()
                
                
                    'File Paths
                    Dim Preplan As String
                    Dim PS_Export As String
                    Preplan = "M:\Template2.xlsx"
                    PS_Export = "M:\PS_Export.xlsx"
                
                    'Open WB's
                    Dim PP_WB As Workbook
                    Dim PS_WB As Workbook
                    Set PP_WB = Workbooks.Open(Filename:=Preplan, Password:="")
                    Set PS_WB = Workbooks.Open(Filename:=PS_Export)
                
                    Dim PP_WS As Worksheet
                    Set PP_WS = PP_WB.Sheets("2017 Pre-Planning Emp Detail")
                    
                    Dim PS_WS As Worksheet
                    Set PS_WS = PS_WB.Sheets("ps")
                    
                    Dim AVCell As Long
                
                
                    
                    lastrow = PP_WS.Range("A" & Rows.Count).End(xlUp).Row
                    lastrow2 = PS_WS.Range("A" & Rows.Count).End(xlUp).Row
                
                    Application.ScreenUpdating = False
                
                
                    PP_WB.Activate
                    
                    With PP_WS
                    
                             
                             With .Range("AE2")
                                 .Formula = "=VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$K,11,FALSE)"
                                 .AutoFill Destination:=Range("AE2:AE" & lastrow)
                             End With
                            
                                With .Range("AF2")
                                    .Formula = "=VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$H,8,FALSE)"
                                    .AutoFill Destination:=Range("AF2:AF" & lastrow)
                                End With
                            
                                    With .Range("AG2")
                                        .Formula = "=VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$AY,50,FALSE)"
                                        .AutoFill Destination:=Range("AG2:AG" & lastrow)
                                    End With
                            
                                          With .Range("AH2")
                                            .Formula = "=VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$O,15,FALSE)"
                                            .AutoFill Destination:=Range("AH2:AH" & lastrow)
                                          End With
                            
                                                With .Range("AI2")
                                                    .Formula = "=VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$P,16,FALSE)"
                                                    .AutoFill Destination:=Range("AI2:AI" & lastrow)
                                                End With
        
                    End With
        
                           PS_WB.Activate
                    
                        With PS_WS
                            .Columns("AH:AH").Insert Shift:=xlToRight
                        
    
    
                           With .Range("AH2")
                                .Formula = "=AD2+AG2"
                                .AutoFill Destination:=Range("AH2:AH" & lastrow2)
                                .Range("AH1") = "Variable Comp"
                           End With
    
                            
                        End With
                             
                                PP_WB.Activate
                                               
                                                
                                With PP_WS
                                             
                                            With .Range("AR2")
                                                 .Formula = "=IF(F2=""X"",VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$AH,34,FALSE),(AS2+AU2+AX2))"
                                                 .AutoFill Destination:=Range("AR2:AR" & lastrow)
                                            End With
             
                                                        With .Range("AS2")
                                                                .Formula = "=IF(F2="""",VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$AD,30,FALSE),(AR2-AX2))"
                                                                .AutoFill Destination:=Range("AS2:AS" & lastrow)
                                                        End With
    
                                                                Range("AT:AV").Insert Shift:=xlToRight
                                                                   
                                                                    
                                                                    
                                                                    With .Range("AT2").Formula = "=IF(F2="""",VLOOKUP(A2,[PS_Export.xlsx]ps!$A:$AD,30,FALSE))"
                                                                           
 .AutoFill Destination:=.Range("AT2:AT" & lastrow) <-------**THIS IS THE ROW WHERE I'M GETTING AN OBJECT REQURIED ERROR**

                                                                            .Range("AU2").Formula = "=IF(F2=""X"",AR2-AX2)"
                                                                            .AutoFill Destination:=.Range("AU2:AU" & lastrow)
                                                                            .Range("AV1") = "2017 Planned Annual IC"
                                                                    End With
                                                              
    
                                                                     For AVCell = 2 To lastrow
                                                                      .Range("AV" & AVCell).Value = .Range("AT" & AVCell).Value & .Range("AU" & AVCell).Value
                
                                                                     Next AVCell
    
    
    
    
    
                                                    End With
 
Last edited by a moderator:
As col AU is all formulas, how do you know which cells should keep the formula & which shouldn't?
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
@Fluff, I'm unsure what you mean, it's not a formula, it's more of a VBA statement:

For AVCell = 2 To lastrow
.Range("AV" & AVCell).Value = .Range("AT" & AVCell).Value & .Range("AU" & AVCell).Value

Next AVCell

I need to just say, in column AU, wherever it returns a number off the formula, bring that over to AV while keeping the formula in the cell as well.

Something like this:


Column AT
Column AU
Column AV (combined result)
0000000

0000000
0000000

0000000
Blank cell
1000000 (=AR30-AX30)
1000000 (=AR30-AX30)
Blank cell
1000000 (=AR31-AX31)
1000000 (=AR31-AX31)
2000000

2000000
2000000

2000000
2000000

2000000

<tbody>
</tbody>
 
Upvote 0
Try this change
Code:
.Range("AU2").Formula = "=IF(F2=""X"",AR2-AX2,"")"
Does that get what you want in col AV
 
Upvote 0
@Fluff, So I made that change to get rid of the errors, and it places the number I want for almost every row. The problem is, is that the formulas for when there's an "X" in column F are brought over in the form of values, not values with a formula in the cell too.

Example:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Column F
[/TD]
[TD]Column AT
[/TD]
[TD]Column AU
[/TD]
[TD]Column AV
[/TD]
[/TR]
[TR]
[TD]X
[/TD]
[TD][/TD]
[TD]860,000 (formula I need to keep in cell too because there's an "X" in Column F)
[/TD]
[TD]860,000 But also include formula from AU
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]100,000
[/TD]
[TD]formula, but I just need number from AT to go to AV, do not transfer AU formula to AV
[/TD]
[TD]100,000, just bring over number from AT, no formula from AU because there's no "X" in column F
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 0"]
<tbody>[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
I'm afraid I've no idea how to do that, assuming it's even possible.
 
Upvote 0
@Fluff, I have a work-around, how would I do this?

I can always the formula in Column AS: =IF(F174="",VLOOKUP(A174,[PS_Export.xlsx]ps'!$A:$AD,30,FALSE),(AR174-AY174))

and then, in column F I could always autofilter to "X" and then I could input this formula (=AR#-AR#) in the first visible cell in column AT.

How would I achieve this without knowing what row the first filtered result falls on? This report will be dynamic, so it wont always be that row number.

Does this make sense?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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