Q:

Pad single-digit numbers with a zero

I have a loop like this to save sheets as CSV files but my first 9 sheets are name liked sinani-01 ... sinani-09 (not like sinani-1 ... sinani-9). How I can concatenate a 0 only before numbers less than 10?
Sub Adder()
    Dim animal As String
    Dim i As Integer
    For i = 1 To 120
        animal = "sinani-" & i
        Sheets(animal).SaveAs "E:\Data\CSV\" & animal & ".csv", xlCSV
    Next i
End Sub

A:

VBA has a Format() function that you can use to pad numbers.
animal = "sinani-" & Format$(i, "00")

This will pad single-digit numbers with a 0. Your two- and three-digit numbers will continue to work as expected.

A:

In the fifth line use the Format function like this:
animal = "sinani-" & Format(i, "#00")

The # means optionally a digit (i.e. present only if there are that many digits in i), 0 means definitely a digit, whereby leading zeros are used if i hasn't got enough digits.

