For i = 01 to 20

  • Thread starter Thread starter Shatin
  • Start date Start date
S

Shatin

I frequently have to run loops which ideally should be like this:

For i = 01 to 20

I need i to be 01 rather than 1 because that's what's the format required in
a string. However, if I type like above, VBA automatically takes away the
zero in 01. So I have to test if i is greater or smaller than 10, and add a
zero back to i if it's < 0. Is there any way I can make VBA accept 01 as a
valid number?
 
If that format is required, use

myString = "something " & Format(i,"00")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
That works. Thanks, Bob!

Bob Phillips said:
If that format is required, use

myString = "something " & Format(i,"00")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

required add
 
Back
Top