EXCEL中VB代码问题(高手请进!)
帮我看下这些代码为什么算不出来。我要在E列写计算式如:5+6*4,在F列显示结果出来如:29。但代码有问题,算不出,本人看不出哪的问题,请高手帮忙!!PrivateSub...
帮我看下这些代码为什么算不出来。我要在E列写计算式如:5+6*4,在F列显示结果出来如:29。但代码有问题,算不出,本人看不出哪的问题,请高手帮忙!!
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Then Exit Sub
If Target.Column <> 5 Then Exit Sub
Dim s As String, r As Range
Application.EnableEvents = False
For Each r In Range("E2:E" & [c65536].End(3).Row)
If r = "" Then r(1, 2) = "": GoTo rNext
s = r.Value
s = Replace(s, "M", "$G$2")
s = Replace(s, "LS", "$G$3")
s = Replace(s, "BGS", "$G$4")
With r(1, 2)
.Value = "=" & s
.Value = .Value
End With
rNext:
Next
Application.EnableEvents = True
End Sub 展开
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Then Exit Sub
If Target.Column <> 5 Then Exit Sub
Dim s As String, r As Range
Application.EnableEvents = False
For Each r In Range("E2:E" & [c65536].End(3).Row)
If r = "" Then r(1, 2) = "": GoTo rNext
s = r.Value
s = Replace(s, "M", "$G$2")
s = Replace(s, "LS", "$G$3")
s = Replace(s, "BGS", "$G$4")
With r(1, 2)
.Value = "=" & s
.Value = .Value
End With
rNext:
Next
Application.EnableEvents = True
End Sub 展开
3个回答
展开全部
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 2 Then Exit Sub
If Target.Column <> 5 Then Exit Sub
Dim s As String, r As Range
Application.EnableEvents = False
For Each r In Target
If r = "" Then r.offset(,1)= "": GoTo rNext
s = r.Value
s = Replace(s, "M", "$G$2")
s = Replace(s, "LS", "$G$3")
s = Replace(s, "BGS", "$G$4")
With r.offset(,1)=
.Value = "=" & s
.Value = .Value
End With
rNext:
Next
Application.EnableEvents = True
End Sub
If Target.Row < 2 Then Exit Sub
If Target.Column <> 5 Then Exit Sub
Dim s As String, r As Range
Application.EnableEvents = False
For Each r In Target
If r = "" Then r.offset(,1)= "": GoTo rNext
s = r.Value
s = Replace(s, "M", "$G$2")
s = Replace(s, "LS", "$G$3")
s = Replace(s, "BGS", "$G$4")
With r.offset(,1)=
.Value = "=" & s
.Value = .Value
End With
rNext:
Next
Application.EnableEvents = True
End Sub
追问
没能解决啊。。With r.offset(,1)=这一行显示红色,错误。出不来结果
追答
不好意思,多了一个等号,应该是:With r.offset(,1) 不是With r.offset(,1)=
或者你原来的代码不动,只要改一句
For Each r In Range("E2:E" & [c65536].End(3).Row)
改成:
For Each r In Target
就可以了
展开全部
If Target.Row < 2 Then Exit Sub 这句去掉试试?
我试了在第2行输入之后能计算出结果
我试了在第2行输入之后能计算出结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-12 · 知道合伙人军队行家
关注
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询