Date issues caused by American format on import

kenderweasel

New Member
Joined
Feb 17, 2017
Messages
40
Hi,

I have a VBA macro that imports data from a saved csvfile into an excel report, however, I'm having problems applying it to a newset of data because the new data has the date in American fomat, not UK.

I need to be able to export the data file with the date in American format,save it as it is (I need this to be as user-friendly as possible, so I don’twant the user to have to make any changes to the file – just save and go), andthen run a macro on the report to import any data on the export that is newerthan the existing data on the report. Ifthere is some way of doing this by keeping the date in US format (as I can setup a formula to change it on the report), then this might be the best option,otherwise, how can I make the macro convert the date before import?


MsgBox ("Select Nuance File")
'Open Nuance File
Dim OpenFileName As String
Dim wb As Workbook
'Select and Open Workbook
OpenFileName = Application.GetOpenFilename("NuanceExport.csv")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)

'Import data - "Raw Data - Nuance" - datedependent
Dim LR1 As Long
Dim LR2 As Long
Dim cl As Range
LR1 = wb.Sheets("Nuance Export").Cells(Rows.Count,"A").End(xlUp).Row
For i = 2 To LR1
Ifwb.Sheets("Nuance Export").Cells(i, "B") >WorksheetFunction.Max(ThisWorkbook.Sheets("Run").Range("$C$6"))And wb.Sheets("Nuance Export").Cells(i, "B") <=ThisWorkbook.Sheets("Run").Range("$C$3") Then
wb.Sheets("Nuance Export").Cells(i, "B").Resize(,5).Copy
LR2 =ThisWorkbook.Sheets("Raw Data - Nuance").Cells(Rows.Count,"B").End(xlUp).Row
ThisWorkbook.Sheets("Raw Data - Nuance").Cells(LR2 + 1,"B").PasteSpecial Paste:=xlPasteValues
End If
Next i
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Which format do you need the dates in?
 
Upvote 0
Kenderweasel,
Here is what I use to turn a U.S. Based Date (MM/DD/YYYY) into a UK type of date (DD.MM.YYYY). I am using periods as the separators in the UK Based date as the database system it is going into needs them to be that way
Code:
counter = 2
OrigDate = Sheet1.Cells(counter, 3).Value
Do While OrigDate <> 0
    OrigDate = Sheet1.Cells(counter, 3).Value
    If OrigDate <> 0 Then
        Sheet1.Cells(counter, 4).Value = Format(OrigDate, "dd.MM.yyyy")    this is the line that does the conversion
        counter = counter + 1
    Else
        GoTo LastLine
    End If
Loop
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top