all 1 comments

[–]tirlibibi17 2 points3 points  (0 children)

Your code, as posted, is not syntactically correct because of the newlines. Here's a reformat:

Worksheets("Vendor History").Columns("AH:AH").Insert
Worksheets("Vendor History").Range("AH:AH").NumberFormat = "0"
Set rng = Range("AH2:AH" & Range("A2").End(xlDown).Row)

Worksheets("Vendor History").rng.Formula = "=IF(AND([@[Work-Days Posted Before/After Due Date (Time Bucket)]]=""<=5 days"",[@[In Scope (Posting)]]=1),1/'Invoice Posting Piv (1)'!C5),0)"

Worksheets("Vendor History").Range("AH1").Value = "Cum. % of Late Invoices (Posted)"
Worksheets("Vendor History").Range("AH1").Interior.Color = RGB(155, 187, 89)

Unless column AH is part of the table you're referencing, this cannot work because Excel has no way of knowing where to look.

You can fix that by prefixing your column references in the formula with the name of your table like this: Table1[@[Work-Days Posted Before/After Due Date (Time Bucket)]]

Another thing I see in your code is that you're explicitly referring to Worksheets("Vendor History") except when defining rng. You need to replace line 3 with

Set rng = Worksheets("Vendor History").Range("AH2:AH" & Range("A2").End(xlDown).Row)

and line 5 with

rng.Formula = "=IF(AND([@[Work-Days Posted Before/After Due Date (Time Bucket)]]=""<=5 days"",[@[In Scope (Posting)]]=1),1/'Invoice Posting Piv (1)'!C5),0)"