Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default How To Loop From File0001.xls To File0150.xls

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default How To Loop From File0001.xls To File0150.xls

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

This works.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default How To Loop From File0001.xls To File0150.xls

Hi Donna

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

HTH. Best wishes Harald

skrev i melding
oups.com...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default How To Loop From File0001.xls To File0150.xls

Thank you very much....you've saved me a lot of trouble.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default How To Loop From File0001.xls To File0150.xls

skrev i melding
oups.com...
Thank you very much....you've saved me a lot of trouble.


Glad to hear that. Thank you for the feedback.

Best wishes Harald


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
How do I create a For loop within a For loop? Linking to specific cells in pivot table Excel Programming 2 January 24th 05 08:05 AM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 11:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"