unable to set formulaarray property of the range class

neveraskedforthis

New Member
Joined
Mar 15, 2019
Messages
1
Hello,

I'm having issues with inputting a formula array into a range of cells. The code in question is as follows:

Code:
theformulapart1 = "=IFNA(INDEX('" & ws & "'!$" & AllelCol & "$1:$" & AllelCol & "$1000" & "X_X_X())"
theformulapart2 = ",MATCH('Allele summary'!$C" & L & "&" & CL & "3" & ",'" & ws & "'!$" & genetypeletter & "$1:$" & genetypeletter & "$1000&'" & ws & "'!$" & HelperCLletter & "$1:$" & HelperCLletter & "$1000,0)),0)"




Sheets("Allele summary").Activate
For K = 0 To 19
L = X + K
Range(CL & L).FormulaArray = theformulapart1
Range(CL & L).Replace "X_X_X())", theformulapart2
CLlastNum = i + lastrow
CLlastLetter = Split(Cells(1, CLlastNum + 1).Address, "$")(1)
Range(CL & L).Select
Selection.AutoFill Destination:=Range(CL & L & ":" & CLlastLetter & L), Type:=xlFillDefault
 Next K

I'm not sure i'm going wrong. Initially i didn't have the replace function, as further up in my code, i have the following code which works fine:

Code:
Sheets("Allele summary").Activate
Range(CL & X).FormulaArray = "=IFNA(INDEX('" & ws & "'!$" & AllelCol & "$1:$" & AllelCol & "$1000,MATCH('Allele summary'!$C" & X & "&" & CL & "3" & ",'" & ws & "'!$" & genetypeletter & "$1:$" & genetypeletter & "$1000&'" & ws & "'!$" & HelperCLletter & "$1:$" & HelperCLletter & "$1000,0)),0)"
CLlastNum = i + lastrow
CLlastLetter = Split(Cells(1, CLlastNum + 1).Address, "$")(1)
Range(CL & X).Select
Selection.AutoFill Destination:=Range(CL & X & ":" & CLlastLetter & X), Type:=xlFillDefault
The only difference is the small loop in the first example so it will add the formula to various rows. but for some reason this iteration of the code doesn't work. I tried the replace function incase it was a character limit issue. Anybody have any ideas? would appreciate any help on the issue
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi,

I think the reason for your error message is invalid "theformulapart1" string. Before moving to the step where VBA replaces "X_X_X())" with theformulapart2, this line needs to return a valid Excel formula:
Code:
Range(CL & L).FormulaArray = theformulapart1

As of now, this line of the code returns the following Array function:
=IFNA(INDEX('Sheet1'!$A$1:$A$1000X_X_X())
As you can see, the formula is invalid and Excel cannot proceed to the next line.

Try modifying this formula to present something that Excel will accept, for example:
Code:
theformulapart1 = "=IFNA(INDEX('" & ws & "'!$" & AllelCol & "$1:$" & AllelCol & "$1000," & "9999),99)"
...and then:
Code:
Range("C10").Replace "9999),99", theformulapart2

Let me know if it worked for you.

P.S. I am also a little bit worried about your theformulapart2 string so maybe try stopping VBA code at some later step, go to Immediate window (Ctrl+G), type in ?theformulapart2 and see if the string is valid.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
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