+ Reply to Thread
Results 1 to 6 of 6

Retrieve Weekday from String

  1. #1
    Registered User
    Join Date
    06-06-2008
    Posts
    5

    Retrieve Weekday from String

    Hey everyone,

    First time poster here, hope I'm doing the right thing.

    I'm attempting to do the following:

    Create two variables myMonthb and myMonthe, which will be used as =Weekday(myMonthb + day + myMonthe). The macro will get the day number from the column to the right of the active cell, and insert it as =Weekday(myMonthb/day/MyMonthe) - the problem I am having is that when I attempt to reference the variables myMonthb and myMonthe in the statement, I get a debug error. I am referencing them in the following way:

    Please Login or Register  to view this content.

    If I simply add the month and date in (as in the code below), the macro works fine.


    Please Login or Register  to view this content.
    Any assistance would be appreciated. Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Does this work?
    Please Login or Register  to view this content.
    The variables must be outside the quotation marks that define the formula, otherwise they're seen as text only.

  3. #3
    Registered User
    Join Date
    06-06-2008
    Posts
    5
    Thanks. That seems to work, but the output into the Formula bar of each cell is below:
    =CHOOSE(WEEKDAY(5/E9/2008), "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    Where it should be:

    Choose(Weekday("5/" & E9 & "/2008")...

    As the middle value is pulled from cell to the right, and the Weekday function doesn't work if used as ("5/E9/2008") or (5/E9/2008).

    Is there a way to simply get the value of E9 in the macro, and then insert it into the formula as the value, rather than a reference to the right cell?

  4. #4
    Registered User
    Join Date
    06-06-2008
    Posts
    5
    Working now with the following code:

    Please Login or Register  to view this content.
    Thanks for your help!

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Why are you using this method?

    There are functions in VBA that could return the text for the weekday.

    For example.
    Please Login or Register  to view this content.
    By the way I can't work with your attachment since it's Excel 2007.

  6. #6
    Registered User
    Join Date
    06-06-2008
    Posts
    5
    Thanks - I'll take a look at that, and in the future will post in 2003 format. As for why, I don't really know, just came to it by searching over the help files. Looks a bit backwards, I know.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. vba code terminates without error
    By aseem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2008, 10:45 PM
  2. RexEx to extract from middle or end of string
    By RobynC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2008, 12:14 PM
  3. VBA Syntax for PDF
    By cvo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2007, 06:59 PM
  4. Desire Versatile Alphanumeric Extractor From Any String
    By bxc2739 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-25-2007, 04:12 PM
  5. processing a string by Excel
    By mark_neil2 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-20-2007, 07:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1