Using Excel 2010 & 2013 (will be used in both versions), what is the best 
way to create a variable date that excludes weekends (and holidays, if 
possible)? 

My scenario, where PrevDate= 2014-Jan-02 and LastDate=2014-Jan-03:

   1. Open an existing workbook with file name: FilePath & PrevDate & 
   "_Outages.xlsx"
   2. Save the workbook with a different file name: FilePath & LastDate & 
   "_Outages.xlsx"
   

 I've tried WORKDAY in VBA, but haven't gotten it to work properly.  My 
last attempt at this was to add the WORKDAY formula in a cell in an open 
workbook, then reference that cell/range in my VBA code.  This is not my 
ideal workaround, however - as I cannot get the file to open using this 
most recent method.

This is very hard to explain when writing it out!  Here's my code.  When I 
run it, I get an error indicating the existing workbook 
(Q:\Transfer\June\VBA\2014-01-02_Outages.xlsx) does not exist - even though 
it does.

    Sheets("Sheet1").Name = "Dates"
    Columns("A:A").Font.Bold = True
    Columns("B:B").NumberFormat = "yyyy-mmm-dd"
    Range("A3") = "TODAY"
    Range("B3").FormulaR1C1 = "=today()"
    Range("A4") = "{last}"
    Range("B4").FormulaR1C1 = "=workday(R[-1]C,-1)"
    Range("A5") = "{prev}"
    Range("B5").FormulaR1C1 = "=workday(R[-2]C,-2)"
    Range("A6") = "{prev}-1"
    Range("B6").FormulaR1C1 = "=workday(R[-3]C,-3)"
    
    Sheets("Dates").Select
    CurrDate = Format(Range("B3"), "yyyy-mmm-dd")
    LastDate = Format(Range("B4"), "yyyy-mm-dd")
    PrevDate = Format(Range("B5"), "yyyy-mm-dd")
    PriorDate = Format(Range("B6"), "yyyy-mm-dd")
    FilePath = "Q:\Transfer\June\VBA\"
        
    Workbooks.Open Filename:=FilePath & PrevDate & "_Outages.xlsx"
    
    ActiveWorkbook.SaveAs Filename:=FilePath & LastDate & "_Outages.xlsx"


Any suggestions?  Thank you so much!

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to