+ Reply to Thread
Results 1 to 7 of 7

Error: Expected end of statement (How to constant Date)

  1. #1
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Error: Expected end of statement (How to constant Date)

    See attached error.

    I am trying to pull historical stock data for STOCKHISTORY function, there are many places using the code STOCKHISTORY function.

    I need to adjust the date range to pull different range of data, but instead of adjusting code in so many places, I would like to use two public variable StartDate and EndDate . Therefore, I only need to adjust these two variable each time when I made the change. For example, I may want to change StartDate to Today()-80 and change EndDate to Today()-15 next time.

    How to define two date variable?

    Thanks.
    Attached Images Attached Images

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Error: Expected end of statement (How to constant Date)

    edit: removed - as, per Greg, this wouldn't work!

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Error: Expected end of statement (How to constant Date)

    Hi there,

    You can't include something which isn't a constant value in a Const declaration statement.

    You CAN combine constant values, e.g.:

    Please Login or Register  to view this content.
    but, as you've found out, including a non-constant value will produce the error you describe.


    Hope this helps.

    Regards,

    Greg M


    P.S. Just for information, when I tried to compile your code, the first instance of "Today" was highlighted, and the error message said "Sub or Function not defined".
    Last edited by Greg M; 09-03-2021 at 07:48 AM. Reason: P. S. added

  4. #4
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Re: Error: Expected end of statement (How to constant Date)

    Quote Originally Posted by Greg M View Post
    Hi there,

    You can't include something which isn't a constant value in a Const declaration statement.

    You CAN combine constant values, e.g.:

    Please Login or Register  to view this content.
    but, as you've found out, including a non-constant value will produce the error you describe.


    Hope this helps.

    Regards,

    Greg M
    Ok, thanks. Then how can I declare 8/15/2021 as constant date? How to write it correctly without error. It is okay to replace Today() with a firm date. If I still want to use public variables StartDate and EndDate.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Error: Expected end of statement (How to constant Date)

    Hi again,

    Something like the following might do what you need:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M

  6. #6
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Re: Error: Expected end of statement (How to constant Date)

    Quote Originally Posted by Greg M View Post
    Hi again,

    Something like the following might do what you need:

    Please Login or Register  to view this content.

    Hope this helps.

    Regards,

    Greg M
    Thanks much!

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Error: Expected end of statement (How to constant Date)

    Hi again,

    Many thanks for your very prompt feedback.

    You're welcome - glad I was able to help.

    Regards,

    Greg M

+ 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. [SOLVED] Complie error Expected: end of statement
    By ax2018 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-01-2018, 12:39 AM
  2. [SOLVED] Expected end of statement error
    By stephme55 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2016, 04:20 PM
  3. [SOLVED] Please help with Expected: end of statement error
    By Ocean Zhang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2015, 03:28 PM
  4. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  5. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  6. Compile Error Expected: End of statement
    By AKarmyguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2010, 02:20 AM
  7. How to fix a Compile Error Expected: End of statement.
    By AKarmyguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2010, 02:19 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