我知道跟随FormulaArray
是一条很长的路线。但我不知道如何解决这个问题,因为它显示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
如果我写的公式没有`IFError()'然后它工作。这是下面给出的代码。
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)"
但我的公式的问题是它返回" #N / A"在工作表'[" & y(UBound(y)) & "]Regelung&Partno'
中找不到匹配时出错。所以我想用IfError()
函数添加公式。但它不起作用
请帮我解决这个问题。
答案 0 :(得分:0)
你好我在这里找到了我的问题的答案。我搜索了互联网并使用.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