调整formulaarray中的公式
我有以下的公式,我想在formulaarray中input,但由于大小的限制,我不能这样做。
=VLOOKUP(MIN(IF(ABS('S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17:$C$42-B5*1000)=MIN(ABS('S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17:$C$42-B5*1000)),IF(ABS('S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17:$C$42-B5*1000)< 500,'S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17:$C$42,))),'S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17:$E$42,3,FALSE)
你上面看到的是VBA程序的结果。 VBA代码中的实际公式如下:
formulaValue = "=VLOOKUP(MIN(IF(ABS('" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17:$C$42-" & ColToSelect & "5*1000)=MIN(ABS('" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17:$C$42-" & ColToSelect & "5*1000)),IF(ABS('" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17:$C$42-" & ColToSelect & "5*1000)< 500,'" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17:$C$42,))),'" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17:$E$42,3,FALSE)" ActiveCell.Formula = formulaValue
有人可以帮我这个吗?
FormulaArray
具有255个字符的限制。
你将不得不拆分Formula
和Replace
部分,使其再次成为整体。
见下面的代码:
Dim Formula As String Dim fLoc As String Formula = "=VLOOKUP(MIN(IF(ABS($C$17:$C$42-B5*1000)=MIN(ABS($C$17:$C$42-B5*1000)),IF(ABS($C$17:$C$42-B5*1000)< 500,$C$17:$C$42,))),$C$17:$E$42,3,FALSE)" fLoc = "'S:\AT Reports\Abhor - Ganganagar\[1 1550 AB.xls]1 1550 A-B'!$C$17" With ActiveCell .FormulaArray = Formula .Replace "$C$17", fLoc End With
编辑:
在你的Formula
更新后,这是如何与variables做到这一点:
Formula = "=VLOOKUP(MIN(IF(ABS($C$17:$C$42-" & ColToSelect & "5*1000)=MIN(ABS($C$17:$C$42-" & ColToSelect & "5*1000)),IF(ABS($C$17:$C$42-" & ColToSelect & "5*1000)< 500,$C$17:$C$42,))),$C$17:$E$42,3,FALSE)" fLoc = "'" & initpath & (n / 3 - 2) & " " & freqSheet & " AB.xls]" & (n / 3 - 2) & " " & freqSheet & " A-B'!$C$17" With ActiveCell .FormulaArray = Formula .Replace "$C$17", fLoc End With