+ Reply to Thread
Results 1 to 4 of 4

Multiple dates format in same column

  1. #1
    Registered User
    Join Date
    09-05-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    3

    Red face Multiple dates format in same column

    Hi guys,

    i am facing a situation where i have multiple format of dates in a column. An example will be row 1-5 will be 15/1/11 and row 6-10 will be 1/15/11. however i am very sure that all these dates are supposed to be January.

    I would like to know if there are anyway to use VBA to format all these date to one standard format???


    Thanks and
    Regard

    Ryan Yu

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,200

    Re: Multiple dates format in same column

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    09-05-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Multiple dates format in same column

    Quote Originally Posted by mikerickson View Post
    Please Login or Register  to view this content.
    Hi this method does convert some values correctly however it is unable to detect situation where the month is january and the dates is less than 12 such as 1st january to 12th january.


    is it possible for me to store a variable such as the month january stored as integer "1"

    and compare the field data example
    if the date is 1/15/2011 then the month is january if the date is 12/1/2011 it will rename to 1/12/2011?

  4. #4
    Registered User
    Join Date
    09-05-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Multiple dates format in same column

    hi i got the solution wish to share with other

    curmonth = 7
    Range("A1").Select
    lastrow = ActiveSheet.UsedRange.Rows.Count
    For i = 2 To lastrow
    ActiveSheet.Cells(i, 5).Select
    ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"

    'excelmonth is the date of the cell
    excelmonth = ActiveSheet.Cells(i, 5)

    'managed to capture the month
    extractmonth = Month(excelmonth)
    If extractmonth = curmonth Then
    ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"
    Else

    'to extract the date and year of excelmonth
    extractdate = Day(excelmonth)
    extractyear = Year(excelmonth)

    'create a new date value
    Dim newdate As Date
    newdate = DateSerial(extractyear, extractdate, extractmonth)
    'write the new date back to cell
    ActiveSheet.Cells(i, 5).Value = newdate

    ActiveSheet.Cells.NumberFormat = "mm/dd/yyyy"
    End If

    Next i
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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