ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 2347|回复: 10

[求助] 多个sheet运用相同的一段代码

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-10-11 19:01 | 显示全部楼层 |阅读模式
一个excel工作簿里面有多个工作表,针对一张表,写了一个代码,现在想把这个代码运用到每一个表中,但是宏的代码不会写,请哪位大咖帮忙解决下。代码如下所示:
Private Sub Worksheet_Change(ByVal TargetAs Range)
If Target.Column = 3 And Target.Count = 1Then
   If IsNumeric(Target.Value) = True Then
       Application.EnableEvents = False
              Target = Target.Value / 100
       Application.EnableEvents = True
   End If
End If
If Target.Column = 8 And Target.Count = 1Then
   If IsNumeric(Target.Value) = True Then
       Application.EnableEvents = False
              Target = Target.Value / 100
       Application.EnableEvents = True
   End If
End If
If Target.Column = 9 And Target.Count = 1Then
   If IsNumeric(Target.Value) = True Then
       Application.EnableEvents = False
              Target = Target.Value / 100
       Application.EnableEvents = True
   End If
End If
If Target.Column = 10 And Target.Count = 1Then
   If IsNumeric(Target.Value) = True Then
       Application.EnableEvents = False
              Target = Target.Value / 100
       Application.EnableEvents = True
   End If
End If
End Sub


TA的精华主题

TA的得分主题

发表于 2018-10-11 19:05 | 显示全部楼层
放在工作簿事件试试

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-10-11 19:09 | 显示全部楼层

工作簿事件试过了,没有效果

TA的精华主题

TA的得分主题

发表于 2018-10-11 19:10 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
我是谁123123 发表于 2018-10-11 19:09
工作簿事件试过了,没有效果

应该上传Excel 表格附件哦

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-10-11 19:15 | 显示全部楼层
不知道为什么 发表于 2018-10-11 19:10
应该上传Excel 表格附件哦

我想把上面的那段代码通过自动加载宏的方式应用到每张表,但是这个宏代码不会编写;每张工作表只需要C列,H列,I列,J列输入的数值自动除以100就可以了

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-10-11 19:28 | 显示全部楼层
不知道为什么 发表于 2018-10-11 19:10
应该上传Excel 表格附件哦

这是excel文件

工作簿.rar

7.16 KB, 下载次数: 4

TA的精华主题

TA的得分主题

发表于 2018-10-11 19:47 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  If Target.Count <> 1 Then Exit Sub
  If Intersect([c:c,h:h,i:i,j:j], Target) Is Nothing Then Exit Sub
  Application.EnableEvents = False
  If Val(Target) Then Target = Target / 100
  Application.EnableEvents = True
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-10-11 20:01 | 显示全部楼层
红旗雪 发表于 2018-10-11 19:47
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  If Target.Count  1 Th ...

谢谢,大佬!这个代码是放在工作簿事件里面的吧

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-10-11 20:03 | 显示全部楼层
红旗雪 发表于 2018-10-11 19:47
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  If Target.Count  1 Th ...

放在模板里面的话,这个代码应该怎么写的呢?

TA的精华主题

TA的得分主题

发表于 2018-10-11 20:38 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
我是谁123123 发表于 2018-10-11 20:03
放在模板里面的话,这个代码应该怎么写的呢?

保存为启用宏?
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-26 19:13 , Processed in 0.042972 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表