两组代码合并后,其中一组无效,请求高手修改!

qq_33669478 2017-08-03 04:07:30
Private Sub worksheet_change(ByVal Target As Range)
If Intersect(Target, [H5,X4]) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Address = "$H$5" Then
[X4] = [H5]
Else
[H5] = [X4]
End If
If Intersect(Target, [H7,y6]) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Address = "$H$7" Then
[y6] = [H7]
Else
[H7] = [y6]
End If
Application.EnableEvents = True
End Sub
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_33669478 2017-08-03
  • 打赏
  • 举报
回复
这位朋友,太谢谢你了。这对我的采矿程序简单化了很多。这是两组代码合并的,遇上三组同样的代码能合并吗?如果能的话请抽时间帮我编一个,不胜感激。
笨狗先飞 2017-08-03
  • 打赏
  • 举报
回复
逻辑上Application.EnableEvents = False  重叠了,而且当[H7,y6]不合条件退出时Application.EnableEvents还是False状态。
笨狗先飞 2017-08-03
  • 打赏
  • 举报
回复
还有错的地方?
笨狗先飞 2017-08-03
  • 打赏
  • 举报
回复
代码没看懂,合并一下还是会的。。。

Private Sub worksheet_change(ByVal Target As Range)
  Application.EnableEvents = False   
  If Not Intersect(Target, [H5,X4]) Is Nothing Then
    If Target.Address = "$H$5" Then
      [X4] = [H5]               
    Else
      [H5] = [X4]
    End If
  End If
 If Not Intersect(Target, [H7,y6]) Is Nothing Then
    If Target.Address = "$H$7" Then
      [y6] = [H7]              
    Else
      [H7] = [y6]              
    End If
  End If 
  Application.EnableEvents = True   
End Sub 

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧