|

楼主 |
发表于 2013-7-5 21:17
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
jsxjd 发表于 2013-7-5 08:23 
你在赋值的时间又进行了一次处理!这里需要循环吗?
这个函数在单个单元格中使用时非常好,我用的循环式为了可以多选操作,比如要清空的时候全选按delete。你的这段代码只能单独使用,多选之后会出错的。我对原来的代码做了修改,请您指正
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Column <> 2 And .Column <> 3 Then Exit Sub
For b = .Row To .Row + .Rows.Count - 1
If Len(Cells(b, .Column)) = 4 Or Len(Cells(b, .Column)) = 3 Then
Application.EnableEvents = False
If Right(Cells(b, .Column), 2) < 60 Then
Cells(b, .Column) = Left(Cells(b, .Column), Len(Cells(b, .Column)) - 2) & ":" & Right(Cells(b, .Column), 2)
End If
Application.EnableEvents = True
Else
End If
Next
End With
End Sub
|
|