Adding a leading number

You have a long list of receipts written down in Excel. The receipts should be numbered. The first one should be 1. Receipt A, second 2. Receipt B and so forth.

This might be the case when you have receipts as hard copies and you need to number the hard copies. Also the Excel numbering must be in sync with numbers in hard copies.

Of course, you can add a column with running number and the combine the two columns.

This is fine, too. Still, you need to create more columns and in real life cases columns F and G might already have been populated.

Another option is to execute the macro below. Place the cursor where the data begins, in D2.

Sub znum()

Dim num

Dim cv

num = 1

Do Until ActiveCell.Value = “”

cv = ActiveCell.Value

ActiveCell.Value = num & “. ” & cv

ActiveCell.Offset(1, 0).Select

num = num + 1

Loop

End Sub

Variable num is increasing by one after every cell. The variable is added in front of the cell context. The cell context is the variable cv. The macro manipulates the cell one by one and stepping down after each cell. When the next empty cell is found, then the macro ends. You cannot have empty lines within the data.

The benefit of the macro is that it is overriding the existing values in D-columns.

Place the cursor in D2 and execute the macro. This is the result.