Results 1 to 4 of 4
  1. #1
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16

    VBA - Number to Date Change

    I have a spreadsheet with a number field that needs to be changed to a date format.

    Field values:



    2092011 Should Be: 09/2/2011
    20092011 Should Be: 09/20/2011
    1102011 10/1/2011
    3092011
    10092011
    16092011
    21092011
    25092011

    So basically the number formats are either "DDMMYYYY" and "DMMYYY" depending on if the date is a single digit or multiple.

    Any help would be appreciated.

    Thanks
    Ryan.

  2. #2
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16
    Basically I need to alter that field depending on the number of characters.

    If the data is 2092011 (7 characters) Then
    =(MID(M2,2,2) & "/" & "0" &LEFT(M2,1) & "/" & RIGHT(M2,4)) = 09/02/2011

    and

    If the data is 20092011 (8 characters) Then
    =(MID(M3,3,2) & "/" & LEFT(M3,2) & "/" & RIGHT(M3,4)) = 09/20/2011

    But not sure how to do this within vba to correct the whole column.

  3. #3
    fpmsi is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2011
    Posts
    16
    Wasnt able to figure out how to do this in vba but simply creating a new column and copy paste special using values i was able to correct my issue

    Code used:
    =IF(LEN(M2)=7,(MID(M2,2,2)&"/"&"0"&LEFT(M2,1)&"/"&RIGHT(M2,4)),(MID(M2,3,2)&"/"&LEFT(M2,2)&"/"&RIGHT(M2,4)))

    Thanks

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    There is always more to learn when you work out the problem yourself, and it did not take very long in your case; less that 1/2 hour. Excellent!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 05-07-2011, 04:24 PM
  2. Option Groups - change value from number to text
    By nchesebro in forum Programming
    Replies: 10
    Last Post: 02-09-2011, 03:52 PM
  3. Can i change the format of DATE () ?
    By Nokia N93 in forum Access
    Replies: 2
    Last Post: 11-27-2010, 01:34 PM
  4. Change date from another control
    By NOTLguy in forum Forms
    Replies: 3
    Last Post: 11-20-2010, 11:24 AM
  5. Change Date Into Number
    By greenbag in forum Queries
    Replies: 0
    Last Post: 11-14-2008, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums