Auto Number increase

MatthewHughes

New Member
Joined
Mar 7, 2018
Messages
6
Hello all.

i have searched this forum and found things very close, But none of them work for my self.

what i need help with is im trying to get a number to auto increase each time the jobsheet is printed,

it will also be accessed by more than one computer/user so also needs no write protection (i dont know how it keeps activating?)

i would upload the file but cant seem to find where to do it.

im using office pro plus 2013 if that makes any difference?

Thank you in advance.
 
Hi Matt,

the below will still work on print, and not on open as requested.

You will need to create a file somewhere called logfile.xlsx and just enter the latest number you have used in cell a1 and save then close.
copy the below macro to the ThisWorkbook section of the VBA editor for the workbook you will be using, and change "c:\test\logfile.xlsx" to the path of your logfile

then save your file (or copy of to test)

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim TW As Workbook
Dim lf As Workbook
Set TW = ThisWorkbook
Set lf = Workbooks.Open("c:\test\logfile.xlsx")
With TW
ActiveSheet.Range("H4").Value = lf.Sheets(1).Range("a1").Value + 1
End With
With lf
Application.ScreenUpdating = False
.Sheets(1).Cells(1, 1).Value = .Sheets(1).Cells(1, 1).Value + 1
lf.Save
lf.Close
Application.ScreenUpdating = True
End With
End Sub

each time you print, it will update the value of H4 in the logfile, so the next time it is printed you will get the next available number.

Like i said, this is not infallible, but the logfile should only be open for a couple of seconds while you print, so the likelyhood of the file being locked is small.


Regards,

Dan.

Can i say a huge thank you.

i have a couple of other little issues (**** networks) that i will sort out but this has been a great help thank you once again.

Matt
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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