.
The following example workbook may be downloaded from this URL :
Auto Increment Col T.xlsb
The macro code contained within the workbook has been tested on Excel 2007, 2010, 2013, 2016. It works successfully on all versions.
Additionally, the code was run on Window 10, Windows 8, Windows 7 and Windows XP. It ran flawlessly on all versions.
The downloaded workbook example functions successfully here after downloading it on several different computers. The macro code does not
depend on API Calls, Formulas (in cells), GUID commands or anything higher in complexity than very basic, simple macro coding. Your project will
not be required to reference any .DLL's, .COM files, the Windows Registry or specialized commands.
COMMAND BUTTON AND MACRO
Create a Command Button on the Worksheet to be utilized. Connect that button to the macro. If you are not familiar how to do these two steps, please Google
"Excel Create Command Button" ... you can also Google "Excel Attach Button To Macro". You will be provided with a plethora of example directions including YouTube
videos that will guide you step by step through the process.
MACRO CODE
Here is the macro code that is located in a REGULAR MODULE :
VBA Code:
Option Explicit
Sub AutoIncremntColT()
Dim i As Integer
Dim cell As Range, rng As Range
Set rng = Range("T5:T5000") 'Edit range here
i = 1
For Each cell In rng
cell.Value = "U-" & Year(Date) & "-000" & i
i = i + 1
Next cell
End Sub
Here is an image, for visual reference, of attaching the Button to the Macro :
Here is an image, for visual reference, of the Macro :
Hopefully reviewing these two images will assist you in the correct steps of creating the button and pasting the macro.
NOTE : THIS MACRO SHOULD ONLY BE RUN ONCE.
It will provide your project with 5000 unique ID's for your project in Col T beginning at row #5.
After completing the above, the user only need enter the Customer Name or other appropriate data in Column A.
The above macro is not dependent on other macros or user actions.
RECOMMENDATION
After running the macro, it is highly recommended the COMMAND BUTTON be removed from the Worksheet. This will prevent accidental
changes to the newly created unique ID's in Column T.
The Command Button may be removed by
RIGHT CLICKING the button, then selecting
CUT.
If it is necessary to recreate the unique ID's in Column T, the COMMAND BUTTON may be recreated, attached to the macro and run the
macro again.