Results 1 to 4 of 4

Thread: Item number with current month

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A:A) is Nothing Then _
           CheckMonthOfItem Intersect(Target, Range"A:A")
    End Sub
    
    Private Sub CheckMonthOfItem(Rng As Range)
    Dim Cel As Range
    
    Application.EnableEvents = False
       For Each Cel in Rng
         If Cel.Address = "A1" Then 
           Cel = "'1/" & Month(Date) 'Special Case
    
    On Error GoTo CelNext
         ElseIf CInt(Split(Cel.Offset(-1), "/")(1)) = Month(Date) Then    
           Cel = CStr(CLng(Split(Cel.Offset(-1), "/")(0) + 1) & "/" & Month(Date)) 'Typical
         ElseIf  CInt(Split(Cel.Offset(-1), "/")(1) = Month(DateAdd( "m", -1, Date) Then 
           Cel = "'1/" & Month(Date) 'New Month
         End If
    CelNext: Err = 0
       Next Cel
    Application.EnableEvents = True
    End Sub
    Last edited by SamT; 11-17-2022 at 03:15 AM. Reason: Added String indicators (" ' ") as needed
    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •