Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is the code for Business Day in VB code

Posted on 2013-11-05
1
Medium Priority
?
260 Views
Last Modified: 2013-11-05
Hi Guys, I currently have a Macro that imports a text file with the Previous Business day in the title. I use this code by naming a range in Excel with the Formula =IF(Now(Weekday (Now)=2, Now-3,Now-1). How can I substitute this in VB code? Here's my current code:
The Range ("AM1") IS THE pREVIOUS wORK DAY FORMULA

Dim target As Range, target1 As Range, target2 As Range, target3 As Range, target4 As Range, target5 As Range, target6 As Range, target7 As Range, target8 As Range, target9 As Range, target10 As Range, target11 As Range
Dim PrevDay, Prevday2 As String

PrevDay = Worksheets("Rec").Range("AM1").Value
PrevDay = Format(PrevDay, "DDMMYY")

Prevday2 = Worksheets("Rec").Range("AM1").Value

Prevday2 = Format(Prevday2, "YYYYMMDD")



    Workbooks.OpenText Filename:= _
        "V:\Treasury Finance Controls\Ledger v SS Recs\EOD Recs\BS\StructNotesBSRec_Daily_" & "*.txt" _
        , Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
        Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
        , 1), Array(16, 1), Array(17, 1), Array(18, 1)), TrailingMinusNumbers:=True
    Workbooks.OpenText Filename:= _
0
Comment
Question by:Justincut
1 Comment
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39624074
Hi,

pls replace
PrevDay = Worksheets("Rec").Range("AM1").Value

Open in new window

with
PrevDay = WorksheetFunction.WorkDay(Date, -1)

Open in new window


or use

PrevDay = Format(WorksheetFunction.WorkDay(Date, -1), "DDMMYY")
Prevday2 = Format(WorksheetFunction.WorkDay(Date, -1), "YYYYMMDD")

Open in new window

Regards
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question