Fiona has attended:
Excel Advanced course
Converting Dates in a CSV file for Stephen
Hi,
We were trying to convert text into dates and dates from the US format into UK format (date from and date to) Please could provide me with the code / solution to be able to apply this to all CSV reports we receive.
Many thanks for your help on this.
Fiona
RE: Converting Dates in a CSV file for Stephen
Hi Fiona
Thank you for your question
The following steps should solve your problem
With the relevant excel file open, go to the visual basic editor by pressing ALT-F11. Then click on the insert menu, select module. In the main code window (Large window on the right) copy and paste the following
Sub DateConverter()
On Error GoTo errorhandler
Dim intCol As Integer
Dim dteDate As Date
Dim strDate As String
Dim intRow As Integer
Dim intStartRow As Integer
Application.ScreenUpdating = False
intCol = CInt(InputBox("Enter Column Number"))
intStartRow = CInt(InputBox("Enter start row"))
For intRow = intStartRow To Cells(5, intCol).CurrentRegion.Rows.Count
dteDate = CDate(Cells(intRow, intCol))
Cells(intRow, intCol) = dteDate
Next intRow
Exit Sub
errorhandler:
MsgBox "Error Number " & Err.Number & vbCrLf & Err.Description
End Sub
If you then go to the developer tab and select the macro button, you will see a macro called DateConverter. When you run the macro it will ask you to specify a column and row number as a start position. (Note columns are here expressed as numbers, so C would be 3)
Hope this works, if you have any difficulkties please let me know.
Regards
Stephen