Find and Replace Macro

MrMiyaghi

New Member
Joined
Dec 19, 2017
Messages
5
Hi all

I have a column that will have a date in multiple cells and every day the date will change. The format of the date is dd/mm/yyyy and I'm trying to create a macro that will select all of the cells and replace the date with 'dd/mm/yyyy (whatever the date is).

Does anybody know the best way to do this?

Thanks in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Do you wish all the cells with dates to be changed to the current date?
 
Upvote 0
Hi Alan

Thanks for the reply.

No I'd like whatever date is in the cell to change.

So if the date in the cell is 21/12/2017 I'd like it to change to '21/12/2017 and if the date in the cell is 22/12/2017 I'd like it to change it to '22/12/2017.

Hopefully that makes more sense
 
Upvote 0
Just to clarify as it might not be that clear.

Whatever date is in the cell I would like to replace it with the same date but with an ' in front of the date
 
Upvote 0
Code:
Option Explicit


Sub convertDates()
    Dim rng As Range
    Dim c As Range
    Set rng = Range("A1").CurrentRegion
    For Each c In rng
        If IsDate(c) Then
            c.NumberFormat = "@"
            c = Format(c, "mm/dd/yyyy") 'change this format to what is correct for your region
        End If
    Next c
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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