|
kwzs_abc 发表于 2013-10-11 15:44
2楼效果好!!就是在C列如遇到相同数据,采取成组输入时或不经意跳行输入时,出现错误!!清风大哥能给个 ... - Private Sub Worksheet_Change(ByVal Target As Range)
- Dim arr
- If Target.Column = 3 Then
- Application.ScreenUpdating = False
- m = Range("c65536").End(xlUp).Row
- n = Range("a65536").End(xlUp).Row + 1
- arr = Range("c2:c" & m)
- For j = 1 To UBound(arr)
- If arr(j, 1) = "" Then
- MsgBox "输入数据出现空白行。", vbOKOnly, "报告"
- Exit Sub
- End If
- Next
- For i = n To m
- If i > 1 And m > n - 1 Then
- If Format(Cells(i, 2), "yyyy") = Format(Cells(i - 1, 2), "yyyy") Then
- Cells(i, 1) = Format(Cells(i, 2), "yyyy") & Format(Right(Cells(i - 1, 1), 3) + 1, "000")
- Else
- Cells(i, 1) = Format(Cells(i, 2), "yyyy") & "001"
- End If
- End If
- Next
- Application.ScreenUpdating = True
- End If
- End Sub
复制代码 |
|