Length Limit for Excel Formula in VBA?

ewong90

New Member
Joined
Mar 14, 2018
Messages
6
Hi!

I have this really long Excel formula that I need to add to my VBA but for some reasons, it feels like there is a length limit for Excel formulas in VBA?

Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the forum.

There's a 255 character limit for the FormulaArray property, but otherwise the limit is the same as if you entered it manually.
 
Upvote 0
Thanks RoryA!

So I'm actually able to put in 990 characters so far in the VBA (I used the Len formula to count the total characters) and the issue arises when I am not able to add in any more characters past 1000-mark.. Do you know a way or a go-around where I can include all of the formula in VBA?

Thanks!
 
Upvote 0
Are you trying to add it all as one line? If so, break it up by concatenating parts, or using a line continuation.
 
Upvote 0
It's a really long formula- not sure how many characters but def more than 1000 characters. How do you use line continuation though?
 
Upvote 0
Like this:

Code:
activecell.formula = "first bit of formula," & _
                                       "second bit of formula," & _
                                       " third bit etc."
 
Upvote 0
Oh that would work- but how do I get VBA to recognize "first bit of formula" is etc etc and "second bit of formula" is etc etc?
 
Upvote 0
It doesn't matter what bits go in where, as it all gets concatenated back into one string before it's put in the cell. You can break lines up in the middle of words if you want.
 
Upvote 0
Tried it but doesn't seem to be working. It has runtime error 1004 where it says application-defined or object-defined error. My formula basically goes like this.

ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]=""ABCD"",""ABCD"",IF......," & _
"IF(AND(RC[-43]=""123456"",IF.....," & _
"IF(AND(RC[-43]=""123456"",IF.....," & _
"IF(AND(RC[-43]=""123456"",IF.....," & _
 
Upvote 0
Put the formula in a string variable and print it to the Immediate window. If it's valid, then you should be able to copy it from there, put Excel in R1C1 mode, paste it in the cell, and see it work.

If you can't, you need to modify the code until you can.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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