-
Formatting dates
In excel, i have dates in column B that are not separated by / /. For example, dates are just listed as:
1312003 -- I would like to write a macro to get this to say 1/31/2003
8312002 -- " " 8/31/2002
10312002 -- " " 10/31/2002
Is there any way can incorporate something in my macro that will look in column B and be able to separate this numbers into date form? Also, I would like to do this for all values in column B, which could range from B1:B100 or B1:B1380, etc..
Thanks for the help
-
[VBA]Sub MakeDate()
Dim rng As Range, cel As Range
Dim Y, M, D
Set rng = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
For Each cel In rng
Y = Right(cel, 4)
D = Mid(cel, Len(cel) - 5, 2)
M = Left(cel, Len(cel) - 6)
cel.Offset(, 1) = DateSerial(Y, M, D)
Next
rng.Offset(, 1).NumberFormat = "mm/dd/yyyy"
End Sub[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
this works great! although it is changing the dates in column C and I need it to change the dates ONLY IN column B.
-
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
oh i see, its taking the results and placing them in column c...
-
thanks for your help, works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules