MACRO won't use CSE Formula (Array Formula)

johnnyb5

Board Regular
Joined
Dec 23, 2014
Messages
89
I use 7 CSE Formulas on a large spreadsheet (one at a time though). When I type them in manually they work fine. However, they are very long so I wanted a MACRO to type them for me. When I try to record this with a MACRO it won't work. Does anyone know if CSE formulas can be used with MACROs or VBA code.

My CSE Formula looks like this:
Range("C2").Select
Selection.FormulaArray = _
"=IF(COUNTIF($A$2:$A2,$A2)=COUNTIF(LIN,$A2), TRIM(ACONCAT(IF(FREQUENCY(IF(EIC<>"",IF(LIN=$A2, MATCH(EIC,EIC,0))),IVEC),""&EIC,""))),"")"

The MACRO changes the cell names to R1C1 format and the code won't appear in the cell (C2) when I stop recording and try to use it. Is there a proper format for using CSE formulas in VBA???
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
First of all the R1C1 code below works fine for me from the recorder

Code:
    Range("C2").FormulaArray = _
        "=IF(COUNTIF(R2C1:R[-12]C1,R[-12]C1)=COUNTIF(LIN,R[-12]C1), TRIM(ACONCAT(IF(FREQUENCY(IF(EIC<>"""",IF(LIN=R[-12]C1, MATCH(EIC,EIC,0))),IVEC),""""&EIC,""""))),"""")"

As for why your code isn't working it is probably just that you haven't doubled your quotes (see how they appear in the R1C1 FORMULA).

I haven't double checked it but try

Code:
Range("C2").FormulaArray = _
 "=IF(COUNTIF($A$2:$A2,$A2)=COUNTIF(LIN,$A2), TRIM(ACONCAT(IF(FREQUENCY(IF(EIC<>"""",IF(LIN=$A2, MATCH(EIC,EIC,0))),IVEC),""""&EIC,""""))),"""")"
 
Upvote 0
First of all the R1C1 code below works fine for me from the recorder

Code:
    Range("C2").FormulaArray = _
        "=IF(COUNTIF(R2C1:R[-12]C1,R[-12]C1)=COUNTIF(LIN,R[-12]C1), TRIM(ACONCAT(IF(FREQUENCY(IF(EIC<>"""",IF(LIN=R[-12]C1, MATCH(EIC,EIC,0))),IVEC),""""&EIC,""""))),"""")"

As for why your code isn't working it is probably just that you haven't doubled your quotes (see how they appear in the R1C1 FORMULA).

I haven't double checked it but try

Code:
Range("C2").FormulaArray = _
 "=IF(COUNTIF($A$2:$A2,$A2)=COUNTIF(LIN,$A2), TRIM(ACONCAT(IF(FREQUENCY(IF(EIC<>"""",IF(LIN=$A2, MATCH(EIC,EIC,0))),IVEC),""""&EIC,""""))),"""")"

Yes Indeed!! My problem with the CSE formulas working inside a MACRO does in fact appear to be the double quotes. It did take a while to correct and run all seven of them but your astute eye and advice were correct.
Thanks Again Mark!
John
 
Upvote 0
Hi John, just to point out that the double quotes don't apply to just array (CSE) formula in VBA, it applies to all formula.
If you want quotes to appear in the formula then you need to double them else VBA thinks you want to put in an empty string.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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