Formatting date values in VBA for various iterations of a date

In Excel VBA I am trying to determine how I can consistently format the below value into dd/mm/yyyy if I receive the cell value provides the below values ?  I tried format.range(***,"dd/mm/yyyy") but the converted values  are inconsistent depending on how someone sends me the values (see below possible received values).

2/1/2017
2/1/17
2/01/17
02/01/2017
02/1/17
02/1/2017


All the above I need to to convert to 01/02/2017
upobDaPlayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:
Hi,

Maybe with the code below, then just input your data in your cells:
Dim wb As Excel.Workbook
Set wb = ThisWorkbook

Dim ws As Excel.Worksheet
Set ws = wb.Worksheets(1)

Dim rng As Excel.Range
Set rng = ws.Range("A1:A10")
rng.NumberFormat = "dd/mm/yyyy"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
upobDaPlayaAuthor Commented:
An edit to the question - Once formatted though I need to store as text and can not drop any leading zeros.  Sorry for the omission.
0
upobDaPlayaAuthor Commented:
Actually this helped...from


Sub SingleQuote()
Dim r As Range, s As String
 
For Each r In Selection
    If Not r.HasFormula Then
        s = r.Text                     ' gets text displayed in cell
        r.NumberFormat = "@"     ' sets cell format as text
        r.Value = s                    ' writes the new value in the cell
    End If
Next r
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.