Question

I'm working with about a 1 million record data set. Currently the data is formatted as the "text" type and I want it to be a "number" type.

I have used the copy special > multiply technique, but the conversion will drop leading zeros in the data set. I do not want this, I want to maintain the fixed lengths of the data inclusive of leading zeros.

How do I do this?

Was it helpful?

Solution

You can use VBA code like the one below, but you still need to insert the logic that will format the i-th column with the right length.

Sub doIt()

    Dim i As Long

    Application.ScreenUpdating = False
    For i = 1 To 10 'replace 10 by the index of the last column of your spreadsheet
        With Columns(i)
            .NumberFormat = String(.Cells(2, 1), "0") 'number length is in second row
        End With
    Next i
    Application.ScreenUpdating = True

End Sub

OTHER TIPS

An option is to set the Cell Format to Custom: Format -> Cell -> Custom: Textbox "Type": max number of zeros

example: 00000 will display 52 as 00052

Note: Make sure the Cell Format is applied to all cells involved in your Paste Special.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top