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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With