View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Paul J[_2_] Paul J[_2_] is offline
external usenet poster
 
Posts: 4
Default Excel VBA to convert "dd.MM.yy" text to "dd/MM/yyyy" format da

Seeing as VBA doesnt handle non-US date formats in this instance, and taking
up ward376's suggestion, I will use the following:

Dim RecordCounter As Long ' Number of Records to be Processed
RecordCounter = 15 ' Including Header
' Reformat dd.MM.yy dates in column F into dd/MM/yyyy Excel dates in column
C via column E
Range("F1").Copy Destination:=Range("E1") ' Copy Header
Dim i As Long
For i = 2 To RecordCounter ' Fill in with Excel formulae
Range("E" & i).FormulaR1C1 = _

"=DATEVALUE(CONCATENATE(LEFT(RC[1],FIND(""."",RC[1])-1),""/"",MID(RC[1],(FIND(""."",RC[1])+1),((FIND(""."",RC[1],(FIND(""."",RC[1])+1))-(FIND(""."",RC[1])+1)))),""/"",RIGHT(RC[1],LEN(RC[1])-FIND(""."",RC[1],FIND(""."",RC[1])+1))))"
Next i
Columns("E:E").NumberFormat = "dd/mm/yyyy;@" ' Format the column
Columns("E:E").Copy ' Copy Values (lose the formulae) and Formats
Columns("C:C").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Columns("C:C").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

It's a bit "intense" but it does the job.

Thanks for all your help.

Paul J