Problem with macro importing date.

Jimbo Razza

Board Regular
Joined
May 21, 2005
Messages
114
Hi There

I have recorded a macro that imports data and splits the data using the text import function set at fixed width.

One of the resulting columns of data is a date.

When I run the macro, any dates from the 1st to the 12th of any month get messed up.

I.e. 01/12/2007 becomes 12/01/2007.

It only does it on dates that range from the 1st to the 12th and all other dates come out fine.

It only does it when I run the macro. When I'm recording the macro or if I do the steps manually, all dates are fine.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
UDF, if you like...
=jimbo(A1)
Code:
Function jimbo(txt As String) As String
With CreateObject("VBScript.RegExp")
     .Pattern = "^((1[0-2]|0[1-9]))/(\d{2})/(\d{4})$"
     jimbo = IIf(.test(txt) = True, .replace(txt,"$3/$1/$4"), txt)
End With
End Function
 
Upvote 0
Code:
' Import and paste file
Dim TooHostToday

        FileToday = InputBox("Todays File Number Please", "Summary Import", "000")

    Workbooks.OpenText Filename:= _
        "\\xxxxx\xxxxx\xxxxx\file" & FileToday & ".TXT" _
        , Origin:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
        Array(Array(0, 1), Array(4, 1), Array(9, 1), Array(20, 1), Array(26, 1), Array(32, 1), _
        Array(38, 1), Array(45, 1), Array(53, 1), Array(59, 1), Array(66, 1)), _
        TrailingMinusNumbers:=True
 
Upvote 0

Forum statistics

Threads
1,222,032
Messages
6,163,506
Members
451,839
Latest member
HonestZed

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