Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

STL - Formerly Best Training Solutions Through Learning
TrustPilot
Excellent
Request Callback We will call you back
0207 987 3777 Call for assistance
Your Basket Basket is empty
converting dates csv file

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Converting Dates in a CSV file for Stephen

Converting Dates in a CSV file for Stephen

ResolvedVersion 2007

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

Mon 19 Oct 2009: Automatically marked as resolved.

Excel tip:

Generate randon numbers

Some types of analysis require you to use randomly generated numbers. You can also use randomly generated numbers to quickly populate an Excel spreadsheet. There's an easy function you can use to do this automatically. Here are a few of the ways you can use it:

Type =RAND() in a cell to generate a number between 0 and 1.
Type =RAND()*100 to generate a number between 1 and 100.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.