|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
再次上交作业,谢谢老师指点!
无限循环的问题,和多个单元格内容添加、删除的问题已经解决,特别是添加时将一列代码向I列复制后,乡镇名称,和乡镇代码一下就出来一片,非常方便,心里也感觉好有成就感,呵呵~~
trustwxq作业-信息录入一举两得.rar
(16.69 KB, 下载次数: 870)
程序代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim rng As Range, rng1 As Range, rng2 As Range, str1 As String, aa As Integer
aa = Sheets("代码").[b65536].End(xlUp).Row
For Each rng1 In Target
If rng1.Column = 9 And rng1.Row > 2 Then
str1 = rng1
If str1 >= "a" And str1 <= "z" Then
str1 = UCase(rng1)
End If
If str1 >= "A" And str1 <= "Z" Then
For Each rng In Sheets("代码").Range("b2:b" & aa)
Set rng2 = rng
If rng.Value = str1 Then
rng1.Resize(1, 2).Value = rng.Offset(0, 1).Resize(1, 2).Value
Exit For
End If
Next
If rng2.Row = aa And rng2.Value <> str1 Then
bb = MsgBox("代码未指定,指定点确定,重输按取消!", vbOKCancel)
If bb = vbOK Then
rng2.Offset(1, -1) = rng2.Offset(0, -1) + 1
rng2.Offset(1, 0).Value = str1
Target.Resize(, 2).Value = ""
Target.Range("a1").Select
Sheets("代码").Activate
rng2.Offset(1, 1).Activate
Application.EnableEvents = True
Exit Sub
Else
Target.Resize(, 2).Value = ""
Target.Range("a1").Select
Application.EnableEvents = True
Exit Sub
End If
End If
ElseIf str1 = "" Then
rng1.Offset(0, 1).Value = ""
End If
End If
Next
Application.EnableEvents = True
End Sub |
|