ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] excel单元格格式中如何设置可以实现我输入一个数字会自动乘上5,比如输1,它自动成5

[复制链接]

TA的精华主题

TA的得分主题

发表于 2009-3-14 08:58 | 显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [A1:H20]) Is Nothing Then    '限制范围
Application.EnableEvents = False  '禁止触发连锁事件
On Error Resume Next     '忽略错误继续执行VBA代码,避免出现错误消息
   
            If Target.Value <> "" Then
            Target = Target.Value * 5

    End If

On Error GoTo 0          '恢复正常的错误提示
Application.EnableEvents = True   '允许触发连锁事件
End If
End Sub

TA的精华主题

TA的得分主题

发表于 2009-3-14 19:06 | 显示全部楼层
建议这样修改一下,避免target里面输入的不是数字.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [A1:H20]) Is Nothing Then    '限制范围
Application.EnableEvents = False  '禁止触发连锁事件
On Error Resume Next     '忽略错误继续执行VBA代码,避免出现错误消息
   
            If  isnumeric(Target.Value) Then      '输入的是数值才进行操作.
            Target = Target.Value * 5
                    End If
Application.EnableEvents = True   '允许触发连锁事件
End If
End Sub

[ 本帖最后由 leitiger 于 2009-3-14 19:08 编辑 ]

TA的精华主题

TA的得分主题

发表于 2009-3-26 23:14 | 显示全部楼层
请问怎么把这段宏代码做到EXCEL里..怎么用?
Dim Rng As Range
Application.EnableEvents = False '禁止触发事件
Set Rng = Range("a1:c5,e1:f5") '你需要的单元格区域
If Intersect(Target, Rng) Is Nothing Then   '选择单元不在区内
  Application.EnableEvents = True           '允许触发事件
  Exit Sub                                  '就退出
End If
On Error GoTo 100
If Target.Value <> ValueBefore Then
  Target.Value = Target.Value * 5
  Application.ScreenUpdating = True
End If
100: '错误处理
If Err.Number = 13 Then
End If
Application.EnableEvents = True '允许触发事件
End Sub

TA的精华主题

TA的得分主题

发表于 2009-3-27 11:28 | 显示全部楼层
哪个会?帮一下..我把这里的宏命令加入里面都不会自动乘..请问怎么加的..不知道我是不是加错了.

TA的精华主题

TA的得分主题

发表于 2009-4-6 09:19 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-4-6 10:38 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2009-4-6 13:13 | 显示全部楼层
43楼:放到
Private Sub Worksheet_Change(ByVal Target As Range)  里面
你的代码
End Sub

TA的精华主题

TA的得分主题

发表于 2009-6-9 10:55 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
请问用一个区域*5,另外一个区域*8又怎么编阿,求教阿,请高手帮忙~~~

TA的精华主题

TA的得分主题

发表于 2009-6-10 08:44 | 显示全部楼层
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo 100
Application.EnableEvents = False '禁止触发事件
If Not Application.Intersect(Target, Union(Range("A1:C5"), Range("E1:F5"))) Is Nothing Then
If Not Application.Intersect(Target, Range("A1:C5")) Is Nothing And Target.Value <> "" Then Target.Value = Target.Value * 5
If Not Application.Intersect(Target, Range("E1:F5")) Is Nothing And Target.Value <> "" Then Target.Value = Target.Value * 8
End If
Application.ScreenUpdating = True
100:
If Err.Number = 13 Then
End If
Application.EnableEvents = True '允许触发事件
End Sub

TA的精华主题

TA的得分主题

发表于 2012-3-31 21:02 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
lhdcxz 发表于 2009-3-12 22:32
有数据的单元格双击后继续变值??看来要增加一个双击事件复原??
这样可以吗?

为请教,什么我复制代码到自己的工作表里不起作用了
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-4-27 04:00 , Processed in 0.031016 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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