excel vba无法运行wps中的语句,用的是office2003版本,

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column > 2 And Target.Column < 40 And Target.Row > 2 And Target.Row < 40 Then
If Cells(23, 3) = 0 Then
Cells(28, 3) = 0
Else
Cells(28, 3) = Cells(23, 3) / Cells(27, 3)
End If
If Cells(25, 3) = 0 Then
Cells(23, 9) = 0
Else
Cells(23, 9) = Cells(25, 3) / Cells(27, 3)
End If
If Cells(26, 3) = 0 Then
Cells(24, 9) = 0
Else
Cells(24, 9) = Cells(26, 3) / Cells(27, 3)
End If

End If
End Sub

上面的代码在excel中是可以正常运行的。但是在wps中不行。要改:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 And Target.Count = 1 And Target.Row > 1 And Target.Cells(1).Value > 0 And VBA.Left(Target.Cells(1).Value, 2) <> "超限" Then
A1 = 70: A2 = 60: A3 = 50: A4 = 40 '这里是四个固定数
S1 = "超限" & Round(Target / A1 * 100, 2) & "%,"
s2 = "超限" & Round(Target / A2 * 100, 2) & "%,"
s3 = "超限" & Round(Target / A3 * 100, 2) & "%,"
s4 = "超限" & Round(Target / A4 * 100, 2) & "%"
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
Target.Validation.Add Type:=xlValidateList, Formula1:=S1 & s2 & s3 & s4
Target.Validation.InCellDropdown = True
End If
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-08
把Private 去掉,然后粘贴到2003VBA应该可以运行。
相似回答