Can formulas be too big for VB

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
I wrote a rather large formula that works in Excel but, when I tried to record it in VB it said it couldn't record. So, I copied it, went into VB and Pasted it. But then I got a compile error. The formula is 562 characters long. Here's the formula:

=IF(AND(C2="New",DCOUNT(BE:BE,1,BE1:BE5)<10),"02-"&"00"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="New",DCOUNT(BE:BE,1,BE1:BE5)<100,DCOUNT(BE:BE,1,BE1:BE5)>=10),"02-"&"0"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="New",DCOUNT(BE:BE,1,BE1:BE5)>99),"02-"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="Change",DCOUNT(BF:BF,1,BF1:BF5)<10),"02-"&"00"&DCOUNT(BF:BF,1,BF1:BF5)&"C",IF(AND(C2="Change",DCOUNT(BF:BF,1,BF1:BF5)<100,DCOUNT(BF:BF,1,BF1:BF5)>=10),"02-"&"0"&DCOUNT(BF:BF,1,BF1:BF5)&"C",IF(AND(C2="Change",DCOUNT(BF:BF,1,BF1:BF5)>99),"02-"&DCOUNT(BF:BF,1,BF1:BF5)&"C",""))))))
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
That's a truely hideous formula :)

Anyway, re the vba - when using the macro recorder, you don't record formulas, you record actions (select cell, change format etc). & the syntax of vba isn't the same as for excel formulas, so unfortunately you can't just pick up a spreadsheet formula & drop it into a macro.

If it works on the sheet, what are you trying to do?

Paddy
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
My question was misleading. I want VB to write the formula into a cell. I've done it a million times before. I record a macro to write the formula into a cell. It was working but I added more arguments to the formula and when I tried to record it I got an error msg saying can't record. It appears that its too big for VB to read. Here's what it looks like in VB:

Range("A2").FormulaR1C1 = "IF(AND(C2="N",DCOUNT(BE:BE,1,BE1:BE5)<10),"02-"&"00"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="N",DCOUNT(BE:BE,1,BE1:BE5)<100,DCOUNT(BE:BE,1,BE1:BE5)>=10),"02-"&"0"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="N",DCOUNT(BE:BE,1,BE1:BE5)>99),"02-"&DCOUNT(BE:BE,1,BE1:BE5)&"N",IF(AND(C2="C",DCOUNT(BF:BF,1,BF1:BF5)<10),"02-"&"00"&DCOUNT(BF:BF,1,BF1:BF5)&"C",IF(AND(C2="C",DCOUNT(BF:BF,1,BF1:BF5)<100,DCOUNT(BF:BF,1,BF1:BF5)>=10),"02-"&"0"&DCOUNT(BF:BF,1,BF1:BF5)&"C",IF(AND(C2="C",DCOUNT(BF:BF,1,BF1:BF5)>99),"02-"&DCOUNT(BF:BF,1,BF1:BF5)&"C",""))))))"
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
I should mention that this formula's funcition is to create a log number. Basically, on another sheet I enter data. I press a button that has a macro assigned to it. The macro, basically, writes links to another sheet. The above formula creates a log number based on the criteria. Its probably a half-*** way of doing it, but it works really well, except for the fact now that I added more arguments to the formula VBA can't seem to record it. Its just seems strange that it works in the cell but VBA can't record it.
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
Nevermind...I figured it out...I forgot that VBA doesn't read text and formulas the same way it looks in Excel...boy, do I feel dumb.
 

Forum statistics

Threads
1,144,510
Messages
5,724,774
Members
422,576
Latest member
kayth891

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
Top