|
本帖最后由 xiaoya6976 于 2023-3-25 14:03 编辑
不知道符合你的意思不,才开始学习VBA,献丑;用Worksheet_SelectionChange事件来写感觉比SUB过程要方便点,直接在G列框选就可以填入号码
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
-
- Dim i, j, rw
- If Err.Number > 0 Then
- If Target.Column = 7 And Target.Offset(0, 1).Value <> "" Then
- Target.Value = "号码"
- End If
- Else
- If Target.Column = 7 Then
- On Error Resume Next '忽略错误继续执行VBA代码,避免出现错误消息
- i = Selection.Rows(Selection.Rows.Count).Row
- j = Selection.Cells(1).Row
- For rw = j To i
- If Cells(rw, 7).Offset(0, 1) <> "" Then
- Cells(rw, 7).Value = "号码"
- Else
- Cells(rw, 7).Value = ""
- End If
- Next
- End If
- End If
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|