Advertisement
dave3009

DRupp

Jul 11th, 2021
1,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Private Sub Worksheet_Change(ByVal Target As Range)
  4. Dim serial As Variant 'current serial number
  5.  
  6. 'turn off events to stop inadvertent looping
  7. Application.EnableEvents = False
  8.  
  9. ' assumes that serial number will be created when column B is altered
  10. If Not Intersect(Target, Range("B:B")) Is Nothing Then
  11.    
  12.     'extract the serial number
  13.    serial = Replace(ThisWorkbook.Names("SerialNumber").Value, "=", "") + 0
  14.    
  15.     'apply to column C (adjust to suit)
  16.    Range("C" & Target.Row).Value = "M-" & serial & Format(Date, "ddmmyy")
  17.    
  18.     'increment serial number
  19.    ThisWorkbook.Names("SerialNumber").RefersTo = serial + 1
  20. End If
  21.  
  22. 'restore events
  23. Application.EnableEvents = True
  24. End Sub
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement