title: Visual Basic - YYYYMMDD HH:MM:SS:MS to
body: <p>I have a Visual Basic script to sort out data from one sheet to another, the only problem is that column B contains date and time in the format of: "<strong>YYYYMMDD HH:MM:SS:???</strong>" as in 20160901 09:36:18:963</p>
  
  <p>And after quite some time spent on google and stackoverflow I haven't found any working solution. I want all my data in columns A, B and C to be sorted after date, longest ago in the top, and the most recent one in the bottom.</p>
  
  <p>Column A and B are then going to be put in to a graph but that is for later.</p>
  
  <p>So in conclusion, I need help both changing my <strong>YYYYMMDD HH:MM:SS:???</strong> as in 20160901 09:36:18:963 into a date format (excel did not seem to recognize it as a date) and also sort the data after date.</p>
  
  <p>Thank in advance!</p>
  
  <p>This is the script as of now:</p>
  
  <pre><code> Sub tjabo_script()
  Dim ArtikelNummer As Variant
  Dim NewSheet As Worksheet
  Dim RowCount As Long
  Dim i As Long, x As Long
  Dim check_value As Range
  ArtikelNummer = InputBox("Skriv in artikelnummer", "Artikelsortering")
  Set NewSheet = Sheets.Add(After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet)
  NewSheet.Name = ArtikelNummer
  
  x = 2 'This is the next empty row on NewSheet.
  With Worksheets("Data")
      RowCount = .Cells(.Cells.Rows.Count, "B").End(xlUp).Row
      For i = 1 To RowCount
          If .Cells(i, 2) = Val(ArtikelNummer) Then
              .Cells(i, 2).Columns("D:D").Copy Destination:= _
                  NewSheet.Cells(x, 1)
              .Cells(i, 2).Columns("N:N").Copy Destination:= _
                  NewSheet.Cells(x, 2)
              .Cells(i, 2).Columns("C:C").Copy Destination:= _
                  NewSheet.Cells(x, 3)
              x = x + 1
          End If
      Next i
  End With
      Application.Worksheets(ArtikelNummer).Range("A1") = "LagerSaldo"
      Application.Worksheets(ArtikelNummer).Range("B1") = "Datum/Tid"
      Application.Worksheets(ArtikelNummer).Range("C1") = "Antal (+/-)"
  End Sub
  </code></pre>