Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    User Defined Function (2000)

    Hi all,

    Seems I am always using the following to show the day of the week. How can I convert the following formula to a custom function in VBA?


    =IF(WEEKDAY(A2)=1,"Sun",IF(WEEKDAY(A2)=2,"Mon",(IF (WEEKDAY(A2)=3,"Tue",IF(WEEKDAY(A2)=4,"Wed",IF(WEE KDAY(A2)=5,"Thur",IF(WEEKDAY(A2)=6,"Fri","Sat")))) )))

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Defined Function (2000)

    This works, but I'm sure there's something better
    <pre>Function MonthName(number As Integer) As String
    Dim Months
    Months = Array("January", "February", "March", "April", _
    "May", "June", "July", "August", _
    "September", "October", "November", "December")
    MonthName = Months(number - 1)
    End Function


    </pre>



    Ian.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: User Defined Function (2000)

    You can custom format the date as "ddd" and avoid all that complexity. (?)
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Defined Function (2000)

    If you insist on a formula, it can be simplified to this:

    =CHOOSE(WEEKDAY(A2),"Sun","Mon","Tue","Wen","Thu", "Fri","Sat")
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: User Defined Function (2000)

    In addition to all the other methods, you could use =TEXT(A2,"ddd").
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: User Defined Function (2000)

    Thanks everybody, didn't know about the "ddd"; that is pretty nifty!

Posting Permissions

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