If Statement Formula not working when recorded in a Macro

isoto

New Member
Joined
Jan 6, 2015
Messages
2
Hello,

I am new to posting in this forum and fairly new to Macros/VBA so please excuse me if I miss anything.

I created the following long formula that gets me the info I need to create an accounts receivable aging report:

=IF(X2="CM", "Credit", IF( X2="PMT", "Unapplied", IF(X2="INV", IF(AND(AB2<=TODAY(),AB2>=TODAY()-7),"0-7",IF(AND(AB2<=TODAY()-8,AB2>=TODAY()-30),"8-30", IF(AB2<=TODAY()-31,">30",IF(AND(AB2>TODAY(),AB2<=(TODAY()+8)),"Within 7",IF(AND(AB2>=(TODAY()+8),AB2<= (EOMONTH(TODAY(),0))),TEXT(TODAY(),"MMMM"), IF(AND(AB2>=EOMONTH(TODAY()+1,0),AB2<=EOMONTH(TODAY(),1)),TEXT(EOMONTH(TODAY(),1),"mmmm"),IF(AB2>EOMONTH(TODAY(),1),TEXT(EOMONTH(TODAY(),1)+1,"MMMM +"), FALSE))))))))))

HXAAABAC
Due DateClassDue CountDue Date FormattedColumn
2015.02.05INV-302/5/2015February

<tbody>
</tbody>

I then recorded a Macro using the formula, which recorded the following:

Code:
ActiveCell.FormulaR1C1 = _
        "=IF(RC[-5]=""CM"",""Credit"",IF(RC[-5]=""PMT"",""Unapplied"",IF(RC[-5]=""INV"",IF(AND(RC[-1]<=TODAY(),RC[-1]>=TODAY()-7),""0-7"",IF(AND(RC[-1]<=TODAY()-8,RC[-1]>=TODAY()-30),""8-30"",IF(RC[-1]<=TODAY()-31,"">30"",IF(AND(RC[-1]>TODAY(),RC[-1]<=(TODAY()+8)),""Within 7"",IF(AND(RC[-1]>=(TODAY()+8),RC[-1]<=(EOMONTH(TODAY(),0))),TEXT(TODAY(),""MMMM""),IF(AND(RC[-1]>=EOMO" & _
        "Y()+1,0),RC[-1]<=EOMONTH(TODAY(),1)),TEXT(EOMONTH(TODAY(),1),""MMMM""),IF(RC[-1]>EOMONTH(TODAY(),1),TEXT(EOMONTH(TODAY(),1)+1,""MMMM +""),FALSE))))))))))"

When I run the macro it gives me the error
"Run-time error '1004':
Application-defined or object-defined or object defined error"


I was reading that Excel only allows 7 nested ifs, is that the issue here?
Any help is greatly appreciated as I am trying to learn.

If it helps, I was also trying to copy what was done in this post with no luck.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I forgot to add that I then use the outcomes in a pivot table like the following:

Row LabelsMarch +FebruaryJanuaryWithin 70-78-30>30CreditGrand Total

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,386
Members
449,221
Latest member
DFCarter

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