简体   繁体   中英

Arrayformula shows error: Unable to set the formulaarray property of the range class

I know following FormulaArray is a long line. But i don't know how to solve this because it shows Run-time error '1004': Unable to set the FormulaArray property of the Range class

Private Sub CommandButton2_Click()
Dim x As Variant
Dim y As Variant

Workbooks.Open (TextBox3.Text)

x = Split(TextBox2.Value, Application.PathSeparator)
y = Split(TextBox3.Value, Application.PathSeparator)

Workbooks(x(UBound(x))).Sheets("KomponentenohneDuplikate").Activate

Workbooks(x(UBound(x))).Sheets("KomponentenohneDuplikate").Range("y5").FormulaArray = "=iferror(INDEX('[" & y(UBound(y)) & "]Regelung&Partno'!C1:C10,MATCH(1,('[" & y(UBound(y)) & "]Regelung&Partno'!C5=RC[-24])*('[" & y(UBound(y)) & "]Regelung&Partno'!C9=""DC""),0),10),""-"")"
With Workbooks(x(UBound(x))).Sheets("KomponentenohneDuplikate").Range("y5:y3263")
.FillDown
.Value = .Value
End With

If I write the formula without `IFError()' then it works. This is code given below.

Workbooks(x(UBound(x))).Sheets("KomponentenohneDuplikate").Range("y5").FormulaArray = "=INDEX('[" & y(UBound(y)) & "]Regelung&Partno'!C1:C10,MATCH(1,('[" & y(UBound(y)) & "]Regelung&Partno'!C5=RC[-24])*('[" & y(UBound(y)) & "]Regelung&Partno'!C9=""DC""),0),10)"

But problem with my formula is that it return "#N/A" error when match is not found in the sheet '[" & y(UBound(y)) & "]Regelung&Partno' . So that i want add the formula with IfError() function. But its not working

Please help me how to solve this.

Hello here i have found answer for my problem. I have searched internet and get correct solution with .Replace function.

Dim FormulaPart1 As String
Dim FormulaPart2 As String
Dim FormulaPart3 As String
Dim origRS As Long

origRS = Application.ReferenceStyle
Application.ReferenceStyle = xlR1C1

FormulaPart1 = "=IFERROR(""Part2"",""-"")"
FormulaPart2 = "INDEX('[" & y(UBound(y)) & "]Regelung&Partno'!C1:C10,""Part3"",10)"
FormulaPart3 = "MATCH(1,('[" & y(UBound(y)) & "]Regelung&Partno'!C5=RC[-25])*('[" & y(UBound(y)) & "]Regelung&Partno'!C9=""Diverse""),0)"

With Workbooks(x(UBound(x))).Worksheets("KomponentenohneDuplikate").Range("z5")

.FormulaArray = FormulaPart1
.Replace what:="""Part2""", replacement:=FormulaPart2, lookat:=xlPart
.Replace what:="""Part3""", replacement:=FormulaPart3, lookat:=xlPart

End With
Application.ReferenceStyle = origRS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM