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.

Solved: have a macro recognize different date formats

Discussion in 'Business Applications' started by mrl, Dec 28, 2012.

Thread Status:
Not open for further replies.
  1. mrl

    mrl Thread Starter

    Joined:
    Aug 12, 2007
    Messages:
    340
    Hi

    First Happy New Year :D

    Is there a way to modify the following to recognize a date that has the format: 2/27/12
    (m/dd/yy). This one only recognizes the standard format: *m/dd/yyyy
    I just want to know in case I need to write a code that has to fine a date with different formats.

    HTML:
    Sub finddate()   
        On Error GoTo Errorline
    Cells.find(Date).Select
        ActiveCell.Offset(0, 1).Range("A1").Select
            Selection.End(xlDown).Select
            ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveWindow.ScrollRow = ActiveCell.Row - 15
    Exit Sub
    Errorline: Call newopen
    End Sub
    
    
    What the code does is look for today’s date in A:A, move over one cell and down to the first empty cell where I can add data.

    If it doesn’t find today’s date, it goes to yesterday’s date and again moves over one cell and down to the first empty cell. Then a messages box pops up and asks if I want today’s date entered (newopen). If no, then it ends. If yes, it brings up another sub that puts todays where I need it (with.. copy-pastespecial-value) moves to the right one cell and I can add data.
    A:A will always have yesterday’s date and sometimes today’s date.

    Mike
     
  2. Garf13LD

    Garf13LD

    Joined:
    Apr 17, 2012
    Messages:
    455
    If your m/dd order is the same, you shouldn't have much problem.
     
  3. mrl

    mrl Thread Starter

    Joined:
    Aug 12, 2007
    Messages:
    340
    Hi Garf13LD,

    Happy New Year

    I don't know what happened :confused:
    I've tried the code with different date formats, but it didn't work.
    After I saw your answer, i tried it again with m/d/yy and it worked perfectly.
    You must have done something to my cpu when I came onto this site :D

    Thanks again

    mike
     
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/1082817

  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