Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1569|回复: 5

[已解决]求大神帮忙改下代码

[复制链接]
发表于 2013-1-7 14:05 | 显示全部楼层 |阅读模式
能帮我改一下下面的代码么,
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
Cells(Target.Row, 11).Value = WorksheetFunction.Text(Now(), "h:m")
End Sub

我想要 在同一行上,当第Column=2时,Column11 显示当前时间,
Column=15时,Column16显示当前时间,
这俩条件同时满足

最佳答案
2013-1-7 14:25
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, 11) = Format(Now(), "h:m")
    If Target.Column = 15 Then Cells(Target.Row, 16) = Format(Now(), "h:m")
End Sub
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2013-1-7 14:13 | 显示全部楼层
If Target.Column <> 2 Then Exit Sub     条件好像与此有冲突吧
回复

使用道具 举报

 楼主| 发表于 2013-1-7 14:16 | 显示全部楼层
E路人 发表于 2013-1-7 14:13
If Target.Column  2 Then Exit Sub     条件好像与此有冲突吧

是冲突的,这个代码只能满足第一个要求,但是想了半天不知道怎么才能满足第二个
回复

使用道具 举报

发表于 2013-1-7 14:25 | 显示全部楼层    本楼为最佳答案   
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, 11) = Format(Now(), "h:m")
    If Target.Column = 15 Then Cells(Target.Row, 16) = Format(Now(), "h:m")
End Sub
回复

使用道具 举报

 楼主| 发表于 2013-1-7 14:34 | 显示全部楼层
zjdh 发表于 2013-1-7 14:25
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, ...

第二个输入 没反应,另外后面用format也不显示
回复

使用道具 举报

 楼主| 发表于 2013-1-7 14:35 | 显示全部楼层
zjdh 发表于 2013-1-7 14:25
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 Then Cells(Target.Row, ...

可以了,不好意思 是我的列隐藏了一列,列数搞错了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-20 16:51 , Processed in 0.220010 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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