Replace code using a loop

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
539
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a group of folders which exist under one main folder as shown below. More will be added in the future but we currently only have "B"-"F" folders (there is no "A" folder).
\\some_server\some_share\main_folder\
\\some_server\some_share\main_folder\B\file.xls
\\some_server\some_share\main_folder\C\file.xls
\\some_server\some_share\main_folder\D\file.xls
\\some_server\some_share\main_folder\E\file.xls
\\some_server\some_share\main_folder\F\file.xls

I'm setting the doing something like this:
bFolder = "\\some_server\some_share\main_folder\B\file.xls"
cFolder = "\\some_server\some_share\main_folder\C\file.xls"
etc.

And then I have an If block where I check the file date against the current date and before I like this:
Code:
If Int(Now) = Int(FileDateTime([B]b[/B]Folder)) Then
' do some stuff
End If
If Int(Now) = Int(FileDateTime([B]c[/B]Folder)) Then
' do some stuff
End If
etc.
Is there a way to update the code and specify that I have folders from B-F and have it loop through the same steps one time for each letter? And if so, is there a way to have it determine B-F without having to hard code that piece of it?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi KGee,

Maybe something like
Code:
Dim i As Long
 
    For i = 1 To 5
        If Int(Now) = Int(FileDateTime("\\some_server\some_share\main_folder\" _
            & Chr(65 + i) & "\file.xls")) Then
            ' do some stuff
        End If
    Next i

HTH

M.
 
Upvote 0
Hi Marcelo,

I didn't get a chance to respond yesterday but this does the trick. I need to make a slight change but I can take figure out the rest based on the code you provided.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top