Formerly Best Training
© 2024 STL. All Rights Reserved.
All prices offered for business users and exclude VAT. E&OE
2nd Floor, CA House, 1 Northey Street, Limehouse Basin, London, E14 8BT. United Kingdom
Forum home » Delegate support and help forum » Microsoft Excel Training and help » Converting Dates in a CSV file for Stephen | Excel forum
Resolved · High Priority · Version 2007
Fiona has attended:
Excel Advanced course
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
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
Mon 19 Oct 2009: Automatically marked as resolved.
|
Excel tip:Freeze Rows and Columns to keep lables displayedYou can freeze rows and columns in your worksheet so they don't move. |
We'll call during UK business hours
Server loaded in 0.09 secs.