Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Date looping

I have gotten my macro working thanks to all of you. Now I'm trying to
make it less interactive for the user (i.e. remove as much human error
as possible in the hands of a not so computer literate person).

To that end, is it possible to create a loop that searches for a file
named “Projections Marc {Date}”, where date is the date that the file
was saved? For example:

Filename = “Projections Marc_2004-06-03.xls”

The search starts with the basic filename of “Projections Marc_” and
runs a loop that begins with the current system date and tries to find
the file. If it fails it removes one day from the date and searches
again. It continues in this manner until it either finds the file, or
it hits the date of the Monday of that week.



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Date looping

Jason,

Here is a shot

testDate = Date
startDate = DateSerial(2004, 1, 1) 'set a limit

Do
If Dir("C:\myTest\Projections Marc_" & Format(testDate,
"yyyy-mm-dd")) < _
"" Then
fFound = True
Else
testDate = testDate - 1
End If
Loop Until fFound Or testDate < startDate


--

HTH

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

"Jason Hancock" wrote in message
...
I have gotten my macro working thanks to all of you. Now I'm trying to
make it less interactive for the user (i.e. remove as much human error
as possible in the hands of a not so computer literate person).

To that end, is it possible to create a loop that searches for a file
named "Projections Marc {Date}", where date is the date that the file
was saved? For example:

Filename = "Projections Marc_2004-06-03.xls"

The search starts with the basic filename of "Projections Marc_" and
runs a loop that begins with the current system date and tries to find
the file. If it fails it removes one day from the date and searches
again. It continues in this manner until it either finds the file, or
it hits the date of the Monday of that week.



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date looping

I assume you want to check the Monday date and then stop.
Dim sName as String, sPath as STring, i as long
Dim bFound as Boolean
sPath = "C:\My Folder\My Files\"
i = 0
bFound = False
Do while Weekday(date - i,vbSunday) 1
sname = sPath & "Projections Marc_" & format(date - i, _
"yyyy-mm-dd" & ".xls"
if dir(sname) < "" then
bFound = True
exit loop
end if
i = i + 1
Loop
if bFound then
workbooks.Open sName
else
msgbox "Not found"
End if

--
Regards,
Tom Ogilvy


"Jason Hancock" wrote in message
...
I have gotten my macro working thanks to all of you. Now I'm trying to
make it less interactive for the user (i.e. remove as much human error
as possible in the hands of a not so computer literate person).

To that end, is it possible to create a loop that searches for a file
named "Projections Marc {Date}", where date is the date that the file
was saved? For example:

Filename = "Projections Marc_2004-06-03.xls"

The search starts with the basic filename of "Projections Marc_" and
runs a loop that begins with the current system date and tries to find
the file. If it fails it removes one day from the date and searches
again. It continues in this manner until it either finds the file, or
it hits the date of the Monday of that week.



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
looping ... date formula ... jer Excel Programming 2 May 24th 04 05:06 PM
Looping Syd[_4_] Excel Programming 1 December 11th 03 11:17 PM
Looping [email protected] Excel Programming 0 October 31st 03 07:47 PM
Need Looping Help [email protected] Excel Programming 2 October 29th 03 08:11 PM


All times are GMT +1. The time now is 08:57 PM.

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"