VB: Macro converting to American dates!

imperium1980

New Member
Joined
Feb 10, 2009
Messages
27
Hi all,
I have put a macro together that pulls data from a sheet which has a date column formatted in standard UK dd/mm/yyyy. Whenever I run the macro it pulls my data together and dumps it into a new sheet called 'Summary' Everything is working fine except VB changes my dates to American formats, i.e 02/01/2012 (2nd Jan) becomes 01/02/2012 (1st Feb). This is driving me nuts! :( Any ideas how I get around this?

Option Explicit
DefInt I-M
DefStr S
Sub Summary()
Dim i, j, k, l, m, iDays
Dim sSummary(), sDate, sMC, sStyle, sPack
Select Case ActiveSheet.Name
Case "January", "March", "May", "July", "August", "October", "December"
iDays = 31
Case "February"
iDays = 29
Case Else
iDays = 30
End Select
l = 0
Range("E7").Select
For i = 0 To iDays - 1
sDate = ActiveCell.Offset(-5, i)
sMC = ActiveCell.Offset(-4, i)
sStyle = ActiveCell.Offset(-3, i)
sPack = ActiveCell.Offset(-2, i)
For j = 0 To 26
If ActiveCell.Offset(j, i) <> "" Then
ReDim Preserve sSummary(7, l)
sSummary(0, l) = sDate
sSummary(1, l) = sMC
sSummary(2, l) = sStyle
sSummary(3, l) = sPack
For m = 4 To 6
'MsgBox ActiveCell.Offset(j, m - 7)
sSummary(m, l) = ActiveCell.Offset(j, m - 7)
Next
sSummary(7, l) = ActiveCell.Offset(j, i)
l = l + 1
End If
Next
Next
Sheets("New Summary").Select
Range("A2").Select
Do
If ActiveCell <> "" Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
For j = 0 To l - 1
For i = 0 To 7
ActiveCell.Offset(j, i) = sSummary(i, j)
Next
Next
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try forcing it to format the way you want.

Format([date or range or whatever], "dd/mm/yyyy")

BTW, most februarys have 28 days ;) ...except leap year of course.
 
Upvote 0
Thanks for the quick response, I tried the forced formatting earlier and it still screws the dates up.

I've already set a reminder in my Outlook to fix the macro for February next year. Providing I get it working that is!
 
Upvote 0
Have you tried just changing the format of the column?

The dates might only be displayed as US dates but the values in the cells are actually 'real' dates.
 
Upvote 0
Hello imperium1980,

You can change the date formats using the Text to Columns... in the Data menu.

  • Select the column of dates and choose Data > Text To Columns. This opens the Convert Text To Columns Wizard .
  • In Step 1 select either option as you only have one column of data selected anyway.
  • Click Next twice.
  • Now in Step Three of the wizard, select the Date option and select the formatting for the displayed data. So if the data has been typed in DMY format, select DMY. If it has been typed in MDY format, choose MDY. Click Finish.
 
Upvote 0
Try Custom function below

Code:
Function ConvertUsDates(aCell)
If IsDate(aCell) Then
    ' Reverse month and day
    ConvertUsDates = DateSerial(Year(aCell), Day(aCell), Month(aCell))
Else
    ConvertUsDates = aCell
End If
End Function

Does it help?

Biz
 
Upvote 0
The only think that might be causing the problem is that the array is declared as string.

Try removing this.
Code:
DefStr S

Or using DateValue, for example.
Code:
sSummary(0, l) = DateValue(sDate)
 
Upvote 0
The only think that might be causing the problem is that the array is declared as string.

Try removing this.
Rich (BB code):
DefStr S

Or using DateValue, for example.
Rich (BB code):
sSummary(0, l) = DateValue(sDate)

:biggrin: Tried the easiest suggestion first and it worked! Thanks to all for offering their wisdom, much appreciated.
Neil
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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