+ Reply to Thread
Results 1 to 14 of 14

VBA to loop different length text dates to convert to Dates

Hybrid View

earlyfreak VBA to loop different length... 06-04-2016, 12:34 PM
shg Re: VBA to loop different... 06-04-2016, 03:08 PM
earlyfreak Re: VBA to loop different... 06-04-2016, 05:28 PM
shg Re: VBA to loop different... 06-04-2016, 05:30 PM
earlyfreak Re: VBA to loop different... 06-04-2016, 07:28 PM
shg Re: VBA to loop different... 06-04-2016, 08:20 PM
earlyfreak Re: VBA to loop different... 06-05-2016, 03:10 AM
shg Re: VBA to loop different... 06-05-2016, 12:48 PM
earlyfreak Re: VBA to loop different... 06-12-2016, 05:53 AM
shg Re: VBA to loop different... 06-12-2016, 03:17 PM
earlyfreak Re: VBA to loop different... 06-13-2016, 03:52 PM
shg Re: VBA to loop different... 06-13-2016, 04:11 PM
earlyfreak Re: VBA to loop different... 06-13-2016, 06:00 PM
shg Re: VBA to loop different... 06-13-2016, 06:15 PM
  1. #1
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to loop different length text dates to convert to Dates

    Sub ef()
      Dim r             As Range
      Dim cell          As Range
      Dim d             As Double
    
      On Error Resume Next
      Set r = ActiveWindow.RangeSelection.SpecialCells(xlCellTypeConstants, xlNumbers).Cells
      If Err.Number Then GoTo NothingToDo
    
      For Each cell In r.Cells
        If VarType(cell.Value) <> vbDate Then
          d = Int(cell.Value2)
          Select Case d
            Case 1000 To 9999
              cell.Value = CDate(Format(d, "0-0-00"))
            Case 10000 To 999999
              cell.Value = CDate(Format(d, "0-00-00"))
            Case Is > 100000
              cell.Value = CDate(Format(d, "0-00-0000"))
          End Select
        End If
      Next cell
    
    NothingToDo:
    End Sub
    Last edited by shg; 06-12-2016 at 05:32 PM.
    Entia non sunt multiplicanda sine necessitate

  2. #2
    Registered User
    Join Date
    06-04-2016
    Location
    New York
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA to loop different length text dates to convert to Dates

    Thanks shg

    That works great for everything but the Date Day,Month 52016 with no day, just month and Year.
    when I run the code it fixes all but makes 52016 into 5/20/2016 which is wrong. This is a weird format that come over in a csv

    everything else is perfect. Don't know how to even attach this one because that could be a 5/20/16 date but comes across as just a month year

    Thanks again for your help, direction and education

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Convert European dates to Excel-read dates
    By thepinkgeologist in forum Excel General
    Replies: 1
    Last Post: 09-21-2015, 10:33 AM
  2. [SOLVED] Convert Text into Dates
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-21-2014, 11:12 AM
  3. Convert Text Dates, Perform Calculation, Convert back to Text
    By Orada in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2012, 05:25 PM
  4. [SOLVED] Request a Macro to Convert data into Dates (Multiple Dates Values separated by Line)
    By seenai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2012, 02:28 AM
  5. Convert Dates in 2011:08:17 format into Dates in Excel
    By JessRI in forum Excel - New Users/Basics
    Replies: 12
    Last Post: 09-11-2012, 09:55 AM
  6. Replies: 1
    Last Post: 06-25-2012, 12:45 AM
  7. Convert Dates to text
    By lmullenjr in forum Excel General
    Replies: 3
    Last Post: 08-18-2006, 10:15 AM

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