Question: I have several revision numbers I need to create folders from. So, lets say `{4, 12, 534}`. From this, I need to create folders that can be sorted accordingly;

```
\004\..
\012\..
\534\..

```

So, what I need to is to get the highest number and then see, how many filling zeros I need for every foldername so they are sorted correct after creating them.

How can I do this using VBA (Excel)? I tried converting them to strings and then dealing around with String operations, but this didn't quite work out.

I hope someone has a nice idea for this...

Answer: 
The simplest way is with `Format` (or `Format$`):

```
dim s As String

    s = Format$(revNum, "000")

```

Using `"000"` as the "format string" tells the function to pad with leading zeros, whereas `"###"` tells it not to pad. The difference between the function versions is the return type: `Format` returns a Variant (String), while `Format$` returns an actual String.
I'm not sure why a simple string operation won't work out.

```
Select Case Len(folderstring)
  Case 1
    folderstring = "00" & folderstring
  Case 2
    folderstring = "0" & folderstring
  Case Else
    ' Do nothing here
End Case

```

OR

```
Dim zeroarray(1 To 3) As Variant

zeroarray = Array("00","0","")
folderstring = zeroarray(Len(folderstring)) & folderstring

```