+ Reply to Thread
Results 1 to 3 of 3

Getting VBA IF statement to behave correctly with =TODAY()

  1. #1
    Registered User
    Join Date
    05-10-2010
    Location
    Gravesend, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Getting VBA IF statement to behave correctly with =TODAY()

    Greetings Excel Forum,

    I am pretty new to using IF statements within VBA, and i'm having a hell of a time trying to get the one i've written to work correctly.

    I am trying to get the formula to perform the "Update Current Date" portion of my code to trigger if the first column in the last row is equal to today's date (so as to update the everchanging data of today's data located in "Summary" sheet.)

    Please Login or Register  to view this content.
    However, statement is coming back as false even if the first column of the last row is today's date (perhaps VBA doesnt like comparing formula answers to hardcoded answers?).

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Getting VBA IF statement to behave correctly with =TODAY()

    Hi Dylan87,

    I put "=TODAY()" in the last cell in Column 'A'.

    The following code worked fine for me (as cut and paste from your sample macro):
    Please Login or Register  to view this content.
    The following may help you debug:
    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    If you need additional help, attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Lewis

  3. #3
    Registered User
    Join Date
    05-10-2010
    Location
    Gravesend, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Getting VBA IF statement to behave correctly with =TODAY()

    Hi LJMetzger,

    Thank you for relplying with your feedback. I'm going to be honest with you, im not sure i'm clever enough to figure out what breakpoints are or how they are meant to be used.

    That being said, i managed to work out a solution to my issue. Turns out you can use DATE instead of trying to formulate todays date with =Today().

    So i changed this line:
    Please Login or Register  to view this content.
    To this:
    Please Login or Register  to view this content.
    And the script now does what i need it to do. Thank you all the same though!

    Dylan.

+ 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] IF statement does not stop correctly
    By heathb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2013, 11:09 AM
  2. If Or Statement not functioning correctly
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2012, 08:08 PM
  3. Why isn't this if statement functioning correctly?!?
    By rmar2011 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-29-2011, 07:31 AM
  4. If statement not adding up correctly
    By sted999 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2010, 10:54 AM
  5. Cannot get chart to behave
    By OdinTGE in forum Excel General
    Replies: 3
    Last Post: 03-18-2010, 06:22 PM
  6. trying to get the RETURN key to behave like the TAB
    By pabs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2010, 09:49 PM
  7. Why does vlookup behave like this?
    By FFrrEEddRRiiKK in forum Excel General
    Replies: 7
    Last Post: 04-05-2009, 08:05 PM

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