Results 1 to 2 of 2

Reformat custom date format

Threaded View

bdb1974 Reformat custom date format 01-28-2011, 04:17 PM
JBeaucaire Re: Reformat custom date... 01-28-2011, 05:03 PM
  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Reformat custom date format

    Hi all,

    I'm hoping someone can help provide a simple solution to a problem that I created by having a custom date format.

    I have 2 columns with dates in a custom format like: yyyy,mm,dd
    I don't think the system recognizes this as a valid date format eventhough I formated
    the cells the custom format mentioned.

    I want to change the format to: mm,dd,yyyy

    I would like to do something like the following:

    Sub FixTimeFormats()
    
    Dim lngYellow As Long
    Dim lngWhite As Long
    Dim I As Integer
    Dim FindIt As Variant
    Dim DF As Worksheet
    Dim WS2 As Worksheet
    
        With ThisWorkbook
        ' ComboBox1.Visible = False
         lngYellow = RGB(252, 248, 61)
        lngWhite = RGB(255, 255, 255)
      
        'Set DF = Sheets("DATEFORMAT")
       Set WS2 = Sheets("Sheet1")
          
    WS2.Activate
    
    
     'Lastrow = WS2.Cells(Rows.Count, "A").End(xlUp).Row
    
         Dim M As String
      Dim D As String
      Dim Y As String
     
     Lastrow = WS2.Cells.Find(What:="*", After:=[K1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row
     
        For Each Cell In Range("$K$8:$K$" & Lastrow, "$Q$8:$Q$" & Lastrow)
        MsgBox Cell.Value & " " & Cell.Row
       A = Cell
        If Cell Like "[0-9][0-9][0-9][0-9][,][0-9][0-9],[0-9][0-9]" Then
       Y = Mid(Cell.Value, 1, 4)
       M = Mid(Cell.Value, 6, 2)
       D = Mid(Cell.Value, 9, 2)
       Cell.Value = M & "/" & D & "/" & Y
       With Cell
       DateFormat = "MM/DD/YYYY"
       End With
       ElseIf Cell Like "[0-9][0-9][/][0-9][0-9][/][0-9]][0-9]" Then
         Y = Mid(Cell.Value, 1, 4)
       M = Mid(Cell.Value, 6, 2)
       D = Mid(Cell.Value, 9, 2)
       Cell.Value = M & "/" & D & "/" & Y
       With Cell
       DateFormat = "MM/DD/YYYY"
       End With
       End If
       
       Next
    
            End With
    
    End Sub
    Any suggestions as to why this is not working?

    I've attached a sample.

    Thanks,

    BDB
    Attached Files Attached Files

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