When using a Macro to do dots to slashes, it changes date to american from UK

Jaffabfc

Board Regular
Joined
Jul 5, 2013
Messages
196
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a macro setup to do lots of things, one including changing dots to slashes in the dates.
The dates would change from 01.10.2020 to 10/01/2020 the format of the cell is correct but it still changes it, anyone any ideas how to sort this?

Really really annoying
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
VBA Code:
Sub Calculate()
'
' Calculate Macro
'

'
    Sheets("Orders").Select
    Range("F:G,I:I").Select
    Range("I1").Activate
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    Range("F:G,I:I,P:P").Select
    Range("P1").Activate
    Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Range("K13").Select
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Sheets("Inventory Report").Select
    Columns("B:B").Select
    Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Range("G38340").Select
    Sheets("No. Of Customers").Select
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Range("G17").Select
    Sheets("Link").Select
    Range("L1").Select
    ActiveCell.Formula2R1C1 = "=LastModified()"
    Range("L2").Select
    Sheets("Sheet3").Select
    Range("B4").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Sheets("Link").Select
End Sub
 
Upvote 0
This is only to show a suggested method. you might need to swithch the dd and mm for your purposes.

VBA Code:
Sub t()
Selection.Replace ".", "/"
Selection = Format(Selection, "dd/mm/yyyy")
End Sub
 
Upvote 0
sorry not very good with macros, the above was just recorded.
where should i put the above code you suggested?
 
Upvote 0
Rich (BB code):
Sub Calculate()
'
' Calculate Macro
'

'
Sheets("Orders").Select
Range("F:G,I:I").Select
Range("I1").Activate
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
Range("F:G,I:I,P:P").Select
Range("P1").Activate
Selection.Replace ".", "/"
Selection = Format(Selection, "dd/mm/yyyy")
Range("K13").Select
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Sheets("Inventory Report").Select
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Range("G38340").Select
Sheets("No. Of Customers").Select
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Range("G17").Select
Sheets("Link").Select
Range("L1").Select
ActiveCell.Formula2R1C1 = "=LastModified()"
Range("L2").Select
Sheets("Sheet3").Select
Range("B4").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("Link").Select
End Sub
 
Upvote 0
Selection.Replace ".", "/" Selection = Format(Selection, "dd/mm/yyyy")

Sorry, been off work so not been able to respond to this.

I have changed the formula as i have added a few columns etc, i have also added what you suggested but i get a runtime error.

can you help?
VBA Code:
Sub Calculate()
'
' Calculate Macro
'

'
    Sheets("Inventory Report").Select
    Columns("B:B").Select
    Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Sheets("No. Of Customers").Select
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
    Sheets("Orders").Select
    Range("H:I,K:K").Select
    Range("K1").Activate
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 6
    Range("H:I,K:K,R:R").Select
    Range("R1").Activate
    Selection.Replace ".", "/"
    Selection = Format(Selection, "dd/mm/yyyy")
    Range("M16").Select
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Columns("C:S").Select
    ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Orders").Sort.SortFields.Add2 Key:=Range( _
        "H2:H13699"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Orders").Sort
        .SetRange Range("C1:S13699")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("B29").Select
    Sheets("Sheet3").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Sheets("Link").Select
    Range("L1").Select
    ActiveCell.Formula2R1C1 = "=LastModified()"
    Range("L1").Select
    ActiveCell.Formula2R1C1 = "=LastModified()"
    Range("L2").Select
    Sheets("Link").Select
    ActiveWindow.SmallScroll Down:=-15
End Sub
 
Upvote 0
The post shows
a) a formula solution
b) Text to Columns solution (date format in Text to Columns DMY)

T202009b.xlsm
AB
101.10.20201-Oct-20
2
301.10.20201-Oct-20
415.01.202015-Jan-20
531.12.202031-Dec-20
6
1c
Cell Formulas
RangeFormula
B1B1=--SUBSTITUTE(A1,".","-")



N.B.
- my regional settings are international dd-mm-yy
- The double negative "--" coerces the text to a number.
Format the dates to your preference.

The Text to Columns with the Macro Recorder produced
Selection.TextToColumns Destination:=Range("B3"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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