Syntax Error While Recording a Macro

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
Hello all,

Aladin helped me out with the following Formula.

Code:
=SUM(IF((WERKBLAD!B6:B1000>=AD2)*(WERKBLAD!B6:B1000<=AE2)*(WERKBLAD!D4:IV4=AF2),IF(WERKBLAD!D6:IV1000="C",8,IF(ISNUMBER(SUBSTITUTE(WERKBLAD!D6:IV1000,"C",0)+0),SUBSTITUTE(WERKBLAD!D6:IV1000,"C",0)+0))))

The problem with it is, that every cell change in my workbook takes now about 15 seconds calculating time.

I thought by putting the formula in a macro and running it only when neccessary to circumvent this problem.

However I can't record the formula, as it keeps on giving a "syntax error in visual basic".

Do you guys know of a solution?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Perhaps like this

Code:
With Range("A1")
    .Formula = "=SUM(IF((WERKBLAD!B6:B1000>=AD2)*(WERKBLAD!B6:B1000<=AE2)*(WERKBLAD!D4:IV4=AF2),IF(WERKBLAD!D6:IV1000=""C"",8,IF(ISNUMBER(SUBSTITUTE(WERKBLAD!D6:IV1000,""C"",0)+0),SUBSTITUTE(WERKBLAD!D6:IV1000,""C"",0)+0))))"
    .Value = .Value
End With
 
Upvote 0
Thank you for your suggestion VoG.

What I forgot to mention is that it concerns a ArrayFormula.

I changed the .Formula part of your code into .FormulaArray
but it results in the following error:
"Unable to set the FormulaArray property of the range class"
 
Upvote 0
As it seems there is no solution for this error, can anyone tell me why this error occurs?
 
Upvote 0
Hello Jonmo,

It's after I changed it to .FormulaArray the error occured?

"Unable to set the FormulaArray property of the range class"
 
Upvote 0
I also tried the following, a clever solution from Andrew Poulsom to deal with lengthy formulas, but the error insists.

It seems the length isn't causing the error, but I can't figure out what it is

Code:
Application.ReferenceStyle = xlR1C1
    With Range("AI2")
        .FormulaArray = "=SUM(IF((WERKBLAD!R[4]C[-33]:R[998]C[-33]>=RC[-5])*(WERKBLAD!R[4]C[-33]:R[998]C[-33]<=RC[-4])*(WERKBLAD!R[2]C[-31]:R[2]C[221]=RC[-3]),IF(WERKBLAD!R[4]C[-31]:R[998]C[221]=""C"",8," & "TheRest)"
        .Replace "TheRest)", "IF(ISNUMBER(SUBSTITUTE(WERKBLAD!R[4]C[-31]:R[998]C[221],""C"",0)+0),SUBSTITUTE(WERKBLAD!R[4]C[-31]:R[998]C[221],""C"",0)+0))))"
    End With
    Application.ReferenceStyle = xlA1
 
Upvote 0
No, neither can I. I can insert the formula manually (it takes several seconds to calculate). Inserting with VBA produces an error.

Can you explain what the formula is meant to do and maybe we can find a completely VBA solution.
 
Upvote 0
Here you find a sample of what I am working on.
The formula is shown in cell K6.
It counts an 8 for each "C" that is found and adds the numbers, following a "C" to it.
it ignores other codes like "CD" etc.
This all based on the criteria given in range J4:L4
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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