I have an excel sheet with a list of numbers that I would like to convert from the number format to text format where all the numbers are 5 characters and preceded by "0"s. In excel I am able to use the =TEXT(A2,"00000") function to achieve the desired results... so for example the number 2 would become "00002" and 847 would become "00847". However, I cannot achieve the same results in my macro with the following code:
This simply produces the same values and even format in the cells it works on. Does anyone have any suggestions on how to handle this?
Code:
LRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
i = 2
Do While i <= LRow
Cells(i, 1).Value = WorksheetFunction.Text(Cells(i, 1).Text, "00000")
i = i + 1
Loop