简体   繁体   English

Arrayformula显示错误:无法设置范围类的FormulaArray属性

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

I know following FormulaArray is a long line. 我知道遵循FormulaArray的行很长。 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 但是我不知道该怎么解决,因为它显示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. 如果我写的公式不带“ IFError()”,那么它将起作用。 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' . 但是我的公式存在问题,当在工作表'[" & y(UBound(y)) & "]Regelung&Partno'找不到匹配项时,它将返回“#N / A”错误。 So that i want add the formula with IfError() function. 所以我想用IfError()函数添加公式。 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. 我搜索了Internet,并使用.Replace函数获得了正确的解决方案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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