Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Unanswered: Help with UDF in VBA wanted

    Hi,

    I am having trouble with the weekday function in my UDF in VBA. I want to calculate the total price of goods purchased with a discount which should be calculated if the orderday is between monday and wednesday and the deliveryday is more than two days from the orderday. I have my if-statement below:

    If Weekday(BDato, vbSunday) > 1 < 5 And Difference > 2 Then
    DiscountDifference = Quantity * Price * 0.025
    Else
    DiscountDifference = 0
    End If

    However, the discount is always 0

    Pleas help

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If Weekday(BDato, vbSunday) > 1 < 5 And Difference > 2 Then
    isnt valid VBA
    If Weekday(BDato, vbSunday) > 1 and Weekday(BDato, vbSunday) < 5 And Difference > 2 Then

    dim DayofWeek as integer
    DayofWeek = Weekday(BDato, vbSunday)
    If DayofWeek > 1 and DayofWeek < 5 And Difference > 2 Then
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    I think your IF statement should be like this
    Code:
    If Weekday(BDato, vbSunday) > 1 And Weekday(BDato, vbSunday) < 5 And Difference > 2 Then
            DiscountDifference = Quantity * Price * 0.025
        Else
            DiscountDifference = 0
        End If
    However, if you alway get 0 as an aswer, then I think Difference is always less than 3 because
    Weekday(BDato, vbSunday) > 1 < 5 is always true because 1 is always less than 5 !!??

    MTB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •