Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim ChkErr As Long
- Dim Txt1 As String
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- On Error GoTo ErrLne
- Dim L1 As Long
- Dim L2 As Long
- Static RngLast As Range
- If Not Application.Intersect(Target, Range("A1:ZZ65000")) Is Nothing Then
- If Not RngLast Is Nothing Then
- If Range(Target.Address).Column = 1 And Range(RngLast.Address).Column = 1 Then
- If RngLast.Address <> Target.Address Then
- 'MsgBox "Lost focus " & RngLast.Address & " " & Range(RngLast.Address).Row & " " & Range(RngLast.Address).Column & " " & RngLast.Value & " Txt1=" & Txt1 & "(" & Len(Txt1) & ")"
- If Txt1 = "" Then
- If Not (RngLast.Value = "") Then
- L1 = 0
- For L2 = 1 To 65500
- If Val(ActiveSheet.Cells(L2, 2)) > L1 Then L1 = Val(ActiveSheet.Cells(L2, 2))
- Next L2
- ActiveSheet.Cells(Range(RngLast.Address).Row, Range(RngLast.Address).Column + 1) = L1 + 1
- End If
- Else
- If RngLast.Value = "" Then
- L1 = ActiveSheet.Cells(Range(RngLast.Address).Row, Range(RngLast.Address).Column + 1)
- ActiveSheet.Cells(Range(RngLast.Address).Row, Range(RngLast.Address).Column + 1) = ""
- For L2 = 1 To 65500
- If Val(ActiveSheet.Cells(L2, 2)) > L1 Then ActiveSheet.Cells(L2, 2) = Val(ActiveSheet.Cells(L2, 2)) - 1
- Next L2
- End If
- End If
- End If
- End If
- End If
- If Range(Target.Address).Column = 1 Then
- Txt1 = Target.Value
- 'MsgBox "Got focus " & Target.Address & " " & Range(Target.Address).Row & " " & Range(Target.Address).Column & " " & Target.Value & " Txt1=" & Txt1 & "(" & Len(Txt1) & ")"
- End If
- Set RngLast = Target
- End If
- Exit Sub
- ErrLne:
- ChkErr = Err.Number
- MsgBox "Error " & Err.Number & " : " & Err.Description, vbInformation
- Resume Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement