将一个 Evaluate 语句的输出传递给另一个。获取错误 2015
Passing output of one Evaluate statement to another. Getting Error 2015
我能够让第一个 Evaluate 函数起作用。但不是第二个。它在 strBulkBP 的第二个 Evaluate 中给出 "Error 2015"。第一个的输出被传递给第二个函数。请帮助修复代码。
谢谢
Sub test1()
Dim strBulkNum as Variant
Dim strBulkBP As Variant
Set wksh3 = Workbooks("Master - Data.xlsx").Sheets("Data")
Set wksh4 = Workbooks("Warranty_Analysis.xlsm").Sheets("TTX-OWNER_data")
Set rngBulkNum = wksh3.Range("BulkNum") 'column A:A
Set rngRefNum = wksh3.Range("RefNum") 'column N:N
Set rngBPNum = wksh4.Range("BPNum") 'column A:A
Set rngBPBulkNum = wksh4.Range("BPBulkNum") 'column E:E
strRefNum = "ES80381"
' The code below works to give a value for strBulkNum = "MX12049"
strBulkNum = Evaluate("=IFERROR(INDEX('[Master - Data.xlsx]Data'!" & rngBulkNum.Address(False, True) & ", SMALL(IF('[Master - Data.xlsx]Data'!" & rngRefNum.Address(False, True) & "=""" & strRefNum & """, ROW('[Master - Data.xlsx]Data'!" & rngRefNum.Address(False, True) & "))," & 2 & ")),"""")")
' The code below does not work. Gives "Error 2015" for strBulkBP
strBulkBP = Evaluate("=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPNum.Address(False, True) & ", SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPBulkNum.Address(False, True) & "=""" & strBulkNum & """,ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPBulkNum.Address(False, True) & "))," & 2 & ")),"""")")
'The below code works - using helper cells & then populating the variable
Set wkshCal = ThisWorkbook.Sheets("Calculation")
Dim FormulaPart1 As String
Dim FormulaPart2 As String
wkshCal.Range("A1") = strBulkNum
FormulaPart1 = "=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$A:$A, xxx()),"""")"
FormulaPart2 = "SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E = $A, ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E)), 1)"
With wkshCal.Range("B1")
.FormulaArray = FormulaPart1
.Replace "xxx()", FormulaPart2
End With
strBulkBP = Range("B1")
End Sub
'下面的代码有效 - 使用辅助单元格然后填充变量。但是,数组公式需要分成两部分,以使其每部分少于 255 个字符。更好的解决方案是变量直接存储计算结果。
设置 wkshCal = ThisWorkbook.Sheets("Calculation")
将 FormulaPart1 调暗为字符串
将 FormulaPart2 变暗为字符串
wkshCal.Range("A1") = strBulkNum
FormulaPart1 = "=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$A:$A, xxx()),"""")"
FormulaPart2 = "SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E = $A, ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E)), 1)"
With wkshCal.Range("B1")
.FormulaArray = FormulaPart1
.Replace "xxx()", FormulaPart2
End With
strBulkBP = Range("B1")
我能够让第一个 Evaluate 函数起作用。但不是第二个。它在 strBulkBP 的第二个 Evaluate 中给出 "Error 2015"。第一个的输出被传递给第二个函数。请帮助修复代码。 谢谢
Sub test1()
Dim strBulkNum as Variant
Dim strBulkBP As Variant
Set wksh3 = Workbooks("Master - Data.xlsx").Sheets("Data")
Set wksh4 = Workbooks("Warranty_Analysis.xlsm").Sheets("TTX-OWNER_data")
Set rngBulkNum = wksh3.Range("BulkNum") 'column A:A
Set rngRefNum = wksh3.Range("RefNum") 'column N:N
Set rngBPNum = wksh4.Range("BPNum") 'column A:A
Set rngBPBulkNum = wksh4.Range("BPBulkNum") 'column E:E
strRefNum = "ES80381"
' The code below works to give a value for strBulkNum = "MX12049"
strBulkNum = Evaluate("=IFERROR(INDEX('[Master - Data.xlsx]Data'!" & rngBulkNum.Address(False, True) & ", SMALL(IF('[Master - Data.xlsx]Data'!" & rngRefNum.Address(False, True) & "=""" & strRefNum & """, ROW('[Master - Data.xlsx]Data'!" & rngRefNum.Address(False, True) & "))," & 2 & ")),"""")")
' The code below does not work. Gives "Error 2015" for strBulkBP
strBulkBP = Evaluate("=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPNum.Address(False, True) & ", SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPBulkNum.Address(False, True) & "=""" & strBulkNum & """,ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!" & rngBPBulkNum.Address(False, True) & "))," & 2 & ")),"""")")
'The below code works - using helper cells & then populating the variable
Set wkshCal = ThisWorkbook.Sheets("Calculation")
Dim FormulaPart1 As String
Dim FormulaPart2 As String
wkshCal.Range("A1") = strBulkNum
FormulaPart1 = "=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$A:$A, xxx()),"""")"
FormulaPart2 = "SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E = $A, ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E)), 1)"
With wkshCal.Range("B1")
.FormulaArray = FormulaPart1
.Replace "xxx()", FormulaPart2
End With
strBulkBP = Range("B1")
End Sub
'下面的代码有效 - 使用辅助单元格然后填充变量。但是,数组公式需要分成两部分,以使其每部分少于 255 个字符。更好的解决方案是变量直接存储计算结果。 设置 wkshCal = ThisWorkbook.Sheets("Calculation") 将 FormulaPart1 调暗为字符串 将 FormulaPart2 变暗为字符串
wkshCal.Range("A1") = strBulkNum
FormulaPart1 = "=IFERROR(INDEX('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$A:$A, xxx()),"""")"
FormulaPart2 = "SMALL(IF('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E = $A, ROW('[Warranty_Analysis.xlsm]TTX-OWNER_data'!$E:$E)), 1)"
With wkshCal.Range("B1")
.FormulaArray = FormulaPart1
.Replace "xxx()", FormulaPart2
End With
strBulkBP = Range("B1")