请您帮我识别并修复我在以下程序中遇到的错误。它说语法错误,我尝试了所有可能的方法输入公式,但我不能。
Dim T As Integer
T = 12
Range("AJ3").Value = "Target ETY"
Range("AJ4").Formula = "=SUM(((Range("A4").Value) * aa), (Range("C4").Value * b), (Range("E4").Value * c), (Range("G4").Value * d), (Range("I4").Value * e), (Range("K4").Value * f), (Range("M4").Value * g), (Range("O4").Value * h), (Range("Q4").Value * i), (Range("S4").Value * j), (Range("U4").Value * k), (Range("W4").Value * l), (Range("Y4").Value * m), (Range("AA4").Value * n), (Range("AC4").Value * o), (Range("AE4").Value * p))"
Range("AJ4").Select
Range("AK3").Value = "Actual ETY"
Range("AK4").FormulaR1C1 = Sum((Range("B4").Value * aa), (Range("D4").Value * b), (Range("F4").Value * c), (Range("H4").Value * d), (Range("J4").Value * e), (Range("L4").Value * f), (Range("N4").Value * g), (Range("P4").Value * h), (Range("R4").Value * i), (Range("T4").Value * j), (Range("V4").Value * k), (Range("X4").Value * l), (Range("Z4").Value * m), (Range("AB4").Value * n), (Range("AD4").Value * o), (Range("AF4").Value * p))
Range("AK4").Select
Range("AL4").Value = Range("AK4").Value / T
Range("AL4").Select
Selection.NumberFormat = "0.0%"
Range("AL3").Value = "Total ETY"
MsgBox "Total ETY for Day" & vbNewLine & Range("AL4").Value
If Range("AL4").Value >= 0 Then
UserForm2.Show
End If
End Sub
答案 0 :(得分:1)
尝试下面的更改
Dim T As Integer, frm As String
T = 12
Range("AJ3").Value = "Target ETY"
frm = "=Sum(A4 * " & aa & ", C4 * " & b & ", E4 * " & c & ", G4 * " & d & ", "
frm = frm & "I4 * " & e & ", K4 * " & f & ", M4 * " & g & ", O4 * " & h & ", "
frm = frm & "Q4 * " & i & ", S4 * " & j & ", U4 * " & k & ", W4 * " & l & ", "
frm = frm & "Y4 * " & m & ", AA4 * " & n & ", AC4 * " & o & ", AE4 * " & p & ")"
Range("AJ4").Formula = frm
Range("AK3").Value = "Actual ETY"
frm = "=Sum(B4 * " & aa & ", D4 * " & b & ", F4 * " & c & ", H4 * " & d & ", "
frm = frm & "J4 * " & e & ", L4 * " & f & ", N4 * " & g & ", P4 * " & h & ", "
frm = frm & "R4 * " & i & ", T4 * " & j & ", V4 * " & k & ", X4 * " & l & ", "
frm = frm & "Z4 * " & m & ", AB4 * " & n & ", AD4 * " & o & ", AF4 * " & p & ")"
Range("AK4").Formula = frm
Range("AL4").Value = Range("AK4").Value / T
Range("AJ4, AK4, AL4").NumberFormat = "0.0%"
Range("AL3").Value = "Total ETY"
MsgBox "Total ETY for Day" & vbNewLine & Range("AL4").Value
If Range("AL4").Value >= 0 Then UserForm2.Show
End Sub
(我不确定aa,b,c,...是因为你的代码不完整,但我认为它们是你想在公式中使用的变量?)