MarkCBB
Active Member
- Joined
- Apr 12, 2010
- Messages
- 497
Hi there VBA Pros,
I am getting the following error when try the run this code (Application-defined or object error 1004)
I have a feeling the formula that I am using is a bit long.
I am getting the following error when try the run this code (Application-defined or object error 1004)
Code:
Sub Filter_PayRoll_Report_PivotTables()
Dim MonthYear_Name As Range
Set MonthYear_Name = Sheet3.Range("E2")
With Application
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
.Calculation = xlManual
End With
With Sheet2.PivotTables("PivotTable2").PivotFields("MONTHYEAR")
.PivotItems(MonthYear_Name.Value).Visible = True
For Each Pi In .PivotItems
If Pi.Name <> MonthYear_Name.Value Then Pi.Visible = False
Next Pi
End With
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
'Need to fix this to be dynamic
With Sheet2
'The error is the below line of code
.Range("C5:AA35").FormulaR1C1 = "=IF(R4C="""","""",IF((RC2-0)>TODAY(),0,IF(RC2="""","""",IF(AND(COUNTIFS(DB_OPS!C10,R4C,DB_OPS!C29,RC2)=0,OR(RC1=""SATURDAY"",RC1=""SUNDAY"")),0,IF(AND((RC2-0)>=VLOOKUP(R4C,DB_AGENTS!C1:C6,6,FALSE),VLOOKUP(R4C,DB_AGENTS!C1:C6,4,FALSE)=""TEAM LEADER"",VLOOKUP(R4C,DB_AGENTS!C1:C6,6,FALSE)<>0),150,IF(AND(VLOOKUP(R4C,DB_AGENTS!C1:C6,6,FALSE)=0,VLOOKUP(R4C,DB_AGENTS!C1:C6)=""TEAM LEADER""),150,IF(AND(VLOOKUP(R4C,DB_AGENTS!C1:C6,6,FALSE)=0,VLOOKUP(R4C,DB_AGENTS!C1:C6,4,FALSE)=""AGENT""),100,100))))+IF(AND(COUNTIFS(DB_OPS!C10,R4C,DB_OPS!C29,RC2)=0,OR(RC1=""Saturday"",RC1=""Sunday"")),0,IF(COUNTIFS(DB_OPS!C10,R4C,DB_OPS!C29,RC2)<CALCULATIONS!R2C9,-(CALCULATIONS!R2C9-COUNTIFS(DB_OPS!C10,R4C,DB_OPS!C29,RC2))*5,IF(COUNTIFS(DB_OPS!C10,R4C,9,RC2)<=CALCULATIONS!R3C9,COUNTIFS(DB_OPS!C10,R4C,DB_OPS!C29,RC2)*1.5))))))"
.Range("C5:AA35").Copy
.Range("C5:AA35").PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False
End Sub
I have a feeling the formula that I am using is a bit long.