How To Loop From File0001.xls To File0150.xls

  • Thread starter Thread starter donna.gough
  • Start date Start date
D

donna.gough

Using....
For j = 1 To 101
FileToOpen = "File000" & j & ".xls"
......
This obviously fails when it tries to open File0010.xls.
Can you loop with it recognising the preceeding 0's in the number ?
I know you can use the length of j to then alter the number of 0's
after the File component by using if/elseifs or case select etc but I'm
sure there must be a way of looping from 0001 to 0010 to 0150.

Question is ...is there ?

Kind Regards
Donna
 
For j = 1 To 11
a = "File" + "0000"
b = Left(a, Len(a) - Len(j)) & j
Next j

This works.
 
Hi Donna

FileToOpen = "File" & Format(j, "0000") & ".xls"

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top