![]() |
How to create an automatic counter
Hi
I have created an excel file to log supplier concern, each concern need a unique reference number Example : 322 Each time i save the file or open the file, i'm saving the associated information, and next time i open again the file, i need the number to become : 323 automatically, so i do not dupplicate the info. Anybody can help? :confused: --- Message posted from http://www.ExcelForum.com/ |
How to create an automatic counter
Hi
What you can do is add the following to your code Sub AutoNew( Order = System.PrivateProfileString("C:\Settings.Txt", "Macrosettings", "Order" If Order = "" The Order = Els Order = Order + End I System.PrivateProfileString("C:\Settings.Txt", "Macrosettings", "Order") = Orde ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#" End Su The first time te file settings.txt will be created. And every time you create a new file, the value = value + 1. Place the field in your document and you have your counter.. Good luck Marco. |
How to create an automatic counter
2 places to store the info: A cell in a (hidden?) worksheet or in th
Names. Range method: Sub WorkbookOpen thisworkbook.sheets(1).range("a1").value thisworkbook.sheets(1).range("a1").value+1 End Sub Names method Sub WorkbookOpen ThisWorkbook.Names(1).Name = "_" (FormatNumber(Right(ThisWorkbook.Names(1).Name Len(ThisWorkbook.Names(1).Name) - 1)) + 1) End Sub Dunca -- Message posted from http://www.ExcelForum.com |
How to create an automatic counter
Hi Marco
I am interested in what you propose ..... Where is the object System.PrivateProfileString ? The code does not work for me. Cheers Nigel "Marco" wrote in message ... Hi, What you can do is add the following to your code: Sub AutoNew() Order = System.PrivateProfileString("C:\Settings.Txt", "Macrosettings", "Order") If Order = "" Then Order = 1 Else Order = Order + 1 End If System.PrivateProfileString("C:\Settings.Txt", "Macrosettings", "Order") = Order ActiveDocument.Bookmarks("Order").Range.InsertBefo re Format(Order, "00#") End Sub The first time te file settings.txt will be created. And every time you create a new file, the value = value + 1. Place the field in your document and you have your counter... Good luck! Marco. |
How to create an automatic counter
Hi Nigel
Just create a sub with the code, and in your macro use Call AutoNe There is no object needed. It's just a system command Regards Marco. |
All times are GMT +1. The time now is 08:49 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com