Date re-formatting (using find & replace) works manually but not via VBA

GillyB

New Member
Joined
Mar 30, 2016
Messages
4
Hi All,

I have searched high and low for a solution to this problem.

The system I use churns out Excel spreadsheets with the date format 00.00.0000 however, to get Excel to recognize this, especially when I want to sort and filter then I need to change the format to 00/00/0000.

When I do this manually I highlight the columns with dates and do a simple find and replace, replacing '.' with '/', it works perfectly, and all the dates are correct.

However when I run my Macro, which includes the code below, a select number of dates are changed to the US format, which messes up all of my worksheet calculations.

Workbooks("Save Here.xls").Worksheets("Save Here").Range("H:I").Select
Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

Workbooks("Save Here.xls").Worksheets("Save Here").Range("G:G").Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

Has anyone seen this before, or something like it? Any help would be much appreciated.

GillyB
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi GillyB, welcome to the board.

What is the format of the cell before you do the search/replace?
 
Upvote 0
Hi GillyB, welcome to the board.

What is the format of the cell before you do the search/replace?

Hi!

The format of the cell is 01.04.2016 but when I run the Macro it changes it to 04/01/2016.

I did post the wrong section of my code in the initial post, I included the next part which takes away blank spaces in column 'G'.

This is the only part of the Macro which deals with the dates.

Workbooks("Save Here.xls").Worksheets("Save Here").Range("H:I").Select
Selection.Replace What:=".", Replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False

P.S. I am on Excel 2003 with Windows XP. I'd be using a more up-to-date version at home, but this is all I have in the office.
 
Upvote 0
Hi GillyB

Assuming it will only be dates in columns H and I try this:

Code:
With Workbooks("Save Here.xls").Worksheets("Save Here")
    .Range("H:H").TextToColumns Destination:=Range("H:H"), DataType:=xlDelimited, FieldInfo:=Array(1, 4)
    .Range("I:I").TextToColumns Destination:=Range("I:I"), DataType:=xlDelimited, FieldInfo:=Array(1, 4)
End With
 
Upvote 0
Hi GillyB

Assuming it will only be dates in columns H and I try this:

Code:
With Workbooks("Save Here.xls").Worksheets("Save Here")
    .Range("H:H").TextToColumns Destination:=Range("H:H"), DataType:=xlDelimited, FieldInfo:=Array(1, 4)
    .Range("I:I").TextToColumns Destination:=Range("I:I"), DataType:=xlDelimited, FieldInfo:=Array(1, 4)
End With

Thank you so much for your help, that worked a treat! :)
 
Upvote 0
Thanks for the feedback, glad it worked :)
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,004
Members
449,203
Latest member
Daymo66

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