Auto Serial number generator that resets to 01 every day

Dave8899

New Member
Joined
Jan 17, 2019
Messages
32
Hi all

Hope you can help i need to crate a serial number generator that creates a new serial number for every entry , and resets to 01 every day.

So far i have, the sheet auto populating The User ID, the date and it crates a Serial number, but i cant think/find a way to get the Serial number to reset to 01 each day.

Top code Add User ID and the Serial number bottom code adds the date.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim i As Long

i = Application.WorksheetFunction.CountA(Sheet1.Range("d:d"))

If i > 1 Then

Sheet1.Range("b" & i).Value = i - 1

i = Application.WorksheetFunction.CountA(Sheet1.Range("d:d"))

If i > 1 Then

Sheet1.Range("c" & i).Value = Application.UserName



End If

End If

End Sub



Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("c:c"), Target)
xOffsetColumn = -2
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = Now
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If
End Sub


sorry cant upload a mini sheet it a works PC and it very restricted :(
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
VBA Code:
If i > 1 Then
If Sheet1.Range("A"&i-1)<>Now then i=2
Sheet1.Range("b" & i).Value = i - 1
 
Upvote 0
Its confusing. Are you changing column D?? Maybe this to replace both? Test it out first.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim datelastran As Date, lr As Long

datelastran = Application.Max(Columns(1))

If Target.Cells.Count = 1 Then
    If Target.Column = 4 Then
        Application.EnableEvents = False
        lr = Range("B" & Rows.Count).End(xlUp).Row
        If datelastran <> Date Or Not IsNumeric(Range("B" & lr).Value) Then
            Target.Offset(0, -2) = 1
        Else
            Target.Offset(0, -2).Value = Range("B" & lr).Value + 1
        End If
        Target.Offset(0, -1) = Application.UserName
        Target.Offset(0, -3) = Date
        Application.EnableEvents = True
    End If
End If

End Sub
 
Upvote 0
Solution
Hi Both, thank for the help, what I'm trying to do is, When the data in column A changes to the next day get the serial number in column B to reset start form 0 again and then continue for the rest of that day and then the next day etc. So may team can have a ref of Date_ serial number _who did it.

Hope this makes sense
 

Attachments

  • Capture.PNG
    Capture.PNG
    8 KB · Views: 18
Upvote 0
But what is the trigger? Changing a cell in column D? If so try what i gave. If not then what is the trigger for the code to fire?
 
Upvote 0
Hi Steve the Fish yes as soon as we put as something column D? I have tried what but sadly no luck
 
Upvote 0
Need a little bit more than sadly no luck. What does that mean? What does it do? On my machine if you type a single value into column D of the sheet where the code is housed then it puts the date into A, a number into B, and the user into C. Yours will do the same under the same conditions.
 
Upvote 0
so sorry, yes I should have explained more, the date appears, the user appears, but the the number column B stays at 1, regardless of the date, when I tested it I had 3 eateries for today, all showing 1 and when I chaged the computer date till tomorrow the same, the date etc update but still just 1 Hope helps a little
 
Upvote 0
Hi Steve, just to let you know it’s working perfectly now there was nothing wrong with your code at all, there must have been with the sheet, no idea what it was possibly something from the others codes stuck or hidden I don’t know, but I opened a new sheet dropped you code in and it worked first time.

thank you so much for your help and apologies for making you doubt yourself.

Dave
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top