VBA & Macro Problems

Generate Sequential BA Serial Numbers in Excel VBA

Olivia MillerOlivia Miller Nov 20, 2026 869 views

Question details

Generate sequential identifiers in column A starting with BA00860 when an Excel VBA user form saves a record.

Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A user form writes record data to columns C through Z and needs to assign an identifier in column A.
Observed behavior
Using MAX with text identifiers produces an incorrect result such as BA01861.
Before you start

Identify the worksheet and the row your user form uses for each new record. Check whether existing identifiers in column A are stored as text; the numeric MAX method below will not count text identifiers.

Solution 1Recommended

Store numeric serials and display the BA prefix with a custom format

Use this approach when column A can store numbers instead of text identifiers.

The stored value 860 appears as BA00860 when the custom number format is applied. MAX can then find the largest numeric value without interpreting the prefix.

If column A already contains text identifiers, convert their numeric portions to numbers before using this method. Keep column A limited to serial numbers and an optional text header.

1
Format the serial number column

Select column A in Excel, open Format Cells, and choose Number > Custom. Enter the format "BA"00000 and select OK.

2
Convert existing text identifiers

If existing entries such as BA00860 are text, use a helper column with =VALUE(MID(A2,3,LEN(A2)-2)), fill it down, then copy and paste the results as values into column A. Apply the custom format again if needed.

3
Assign the next number in VBA

Open the VBA editor with Alt+F11 and add the following logic to the user form's save routine. Replace Sheet1 with your worksheet name and use nextRow for the form data in columns C through Z: Dim ws As Worksheet Dim nextRow As Long Set ws = ThisWorkbook.Worksheets("Sheet1") nextRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row + 1 ws.Cells(nextRow, "A").NumberFormat = """BA""00000" ws.Cells(nextRow, "A").Value = Application.WorksheetFunction.Max(859, Application.WorksheetFunction.Max(ws.Columns("A"))) + 1

4
Test the user form

Save a record through the user form and check column A. With no existing numeric serials, the first value should display as BA00860; the next should display as BA00861.

Store numeric serials and display the BA prefix with a custom format
Row and sequence considerations: The sample finds the next row from column C, so adjust it if column C can be blank or your form already determines the target row. MAX uses the largest remaining number, so deleting the latest record can allow that number to be reused.
Free Microsoft Office alternative

Work with Serial Number Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Office formats, making it easy to move and edit workbooks. Check macro support in your WPS version before relying on an Excel VBA user form.

Format and edit serial number columns in spreadsheets.Open and save Microsoft Excel workbook formats, including XLSX.Use a familiar interface to migrate everyday spreadsheet work.Get a lightweight office suite with a free version.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't MAX find my BA-prefixed identifiers?

Identifiers such as BA00860 are text when entered with the prefix, and MAX ignores text in a range. Store 860 as a number and use the custom format "BA"00000 to display the prefix.

How do I start the sequence at BA00860?

Use 859 as the minimum value in the VBA calculation, then add 1. Apply the custom format "BA"00000 to the destination cell so 860 displays as BA00860.

Can I keep existing BA identifiers?

Yes. Convert the numeric portion of each text identifier to a number, paste the results as values in column A, and apply the custom format "BA"00000. Verify the displayed identifiers before using the VBA routine.

Will the custom format change the stored value?

No. The format changes only how the value appears in Excel. For example, a cell displaying BA00860 still stores the number 860.

What happens after BA99999?

The next numeric value, 100000, displays as BA100000. The five zeros in the custom format set a minimum number of digits, not a maximum.