1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

working with dates in Excel

Discussion in 'Business Applications' started by PincivMa, Oct 17, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    Hi there

    I'm having problems with dates in a macro. To simplify things, here is an example of my problem. I have code that goes something like this:

    Range("K1").Select
    Do
    If Range("k1") <= Range("D9") then
    ActiveCell.Offset(0, -1).Range("A1") .select
    End If
    Loop Until ActiveCell >=Range("K1") or ActiveCell = ActiveCell.Text

    Cells K1 and Cells D9, C9 and B9 all have dates. Assume that the dates are as follows:
    K1 = Sept 05, 2005
    D9 = Oct 15, 2005
    C9 = Sept 05, 2005
    B9 = Aug 2, 2005
    A9 = text

    The problem is that the cursor stops at the text cell (A9) and completely by-passes all the dates. It should stop at Cell C9. If C9 did not equal K1, then the cursor should stop at cell D9.

    The macro works fine if I take out the inequality signs and just leave the equal signs. What Am I doing wrong??

    Please help.

    Mario
     
  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,679
    Are the dates just dates or date & time?
    Why have you got Range("A1") in the ActiveCel statement, why not use plain
    ActiveCell.Offset(0, -1).select
     
  3. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,679
    The test signs or in the wrong order
    Loop Until ActiveCell >=Range("K1")
    should be
    Loop Until ActiveCell =>Range("K1")
     
  4. PincivMa

    PincivMa Thread Starter

    Joined:
    Mar 13, 2004
    Messages:
    378
    Hi OBP

    You have the signs in the wrong order, since the Macro does not accept =>. It only accepts >=.

    I have only dates; not dates and time.

    Any other suggestions why my macro does not work properly??
     
  5. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,679
    PincivMa, I have tested it using =>Range("K1") and it works OK.
     
  6. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,679
    Please see attached Excel spreadsheet, the command button has the VBA that does as I said.
     

    Attached Files:

  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/408543

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice