Excel 用VBA实现变量计算公式
我正在绞尽脑汁研究这一行代码的语法。带有“IfError”的公式似乎语法错误。我相信我在正确的地方引用了这些话Excel 用VBA实现变量计算公式,excel,vba,excel-formula,Excel,Vba,Excel Formula,我正在绞尽脑汁研究这一行代码的语法。带有“IfError”的公式似乎语法错误。我相信我在正确的地方引用了这些话 Dim j As Integer Dim MidPointE As String Dim Dist As String Dim Allocation As String MidPointE = "AM" Dist = "AN" Allocation = "AO" for J= 1 to 300 Cells(j,
Dim j As Integer
Dim MidPointE As String
Dim Dist As String
Dim Allocation As String
MidPointE = "AM"
Dist = "AN"
Allocation = "AO"
for J= 1 to 300
Cells(j, Dist).Formula = "=IFERROR(" & MidPointE & j & " / " & MidPointE & CustomerLast & ", "")"
Cells(j, Allocation).Formula = "=" & Allocation & j & "* S" & CustomerLast
Next J
尝试:
字符串文字中的引号必须转义,这可以通过将引号加倍来完成。尝试:
字符串文本中的引号必须转义,这是通过将它们加倍来完成的。它在这里的末尾
& ", "")"
逗号和之间的两个引号)结束字符串并开始一个新字符串
'first string
","
'second string
")"
既然你不能像那样把两个字符串放在一起,我会用CHR等价物替换这两个引号。应该是这样的:
Cells(j, Dist).Formula = "=IFERROR(" & MidPointE & j & " / " & MidPointE & CustomerLast & ", "& CHR(034) & CHR(034) & ")"
'pretty sure 034 is the ascii code for "
在这里的尽头
& ", "")"
逗号和之间的两个引号)结束字符串并开始一个新字符串
'first string
","
'second string
")"
既然你不能像那样把两个字符串放在一起,我会用CHR等价物替换这两个引号。应该是这样的:
Cells(j, Dist).Formula = "=IFERROR(" & MidPointE & j & " / " & MidPointE & CustomerLast & ", "& CHR(034) & CHR(034) & ")"
'pretty sure 034 is the ascii code for "
也可以同时指定多个公式:
Range("AN1:AN300").Formula = "=IFERROR(AM1 / AM$" & CustomerLast & ", """")"
Range("AO1:AO300").Formula = "=AO1 * S$" & CustomerLast
我还建议查看Excel表格和
为避免循环引用问题,可以计算公式并直接指定值:
Range("AN1:AN300") = Evaluate("IFERROR(AM1:AM300 / AM$" & CustomerLast & ", """")")
Range("AO1:AO300") = Evaluate("INDEX(AO1:AO300 * S$" & CustomerLast & ",)")
也可以同时指定多个公式:
Range("AN1:AN300").Formula = "=IFERROR(AM1 / AM$" & CustomerLast & ", """")"
Range("AO1:AO300").Formula = "=AO1 * S$" & CustomerLast
我还建议查看Excel表格和
为避免循环引用问题,可以计算公式并直接指定值:
Range("AN1:AN300") = Evaluate("IFERROR(AM1:AM300 / AM$" & CustomerLast & ", """")")
Range("AO1:AO300") = Evaluate("INDEX(AO1:AO300 * S$" & CustomerLast & ",)")
&“,”)“
末尾应该是&“,”)“
FWIW-单元格(j,分配)。公式=“=”&Allocation&j&“*S”&CustomerLast
(在您为CustomerLast
赋值后)将导致循环引用错误。谢谢!我以前试过,但得到确认后,它突然起作用了<代码>&“,”)“末尾应该是&“,”)“
FWIW-单元格(j,分配)。公式=“=”&Allocation&j&“*S”&CustomerLast
(为CustomerLast
赋值后)将导致循环引用错误。谢谢!我以前试过,但得到确认后,它突然起作用了!AO单元仍然会产生一个循环引用,但只有OP能解决这个问题,AO单元仍然会产生一个循环引用,但只有OP能解决这个问题。