Convert time and date which are text to proper time and date

uk747

Well-known Member
Joined
Jul 20, 2011
Messages
832
Office Version
  1. 365
Platform
  1. Windows
I have times in H1:Q1 which are formatted as hh:mm but are actually text
E.g. 04:20. 05:11

I also have dates in h3:Q3 which are formatted as dd-mm-yy are also text

I would like VBA to convert the times to proper times and dates to proper dates

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Thanks
I know about the formulas, but how would I use it within VBA to convert the 2 ranges
 
Upvote 0
Thanks
I know about the formulas, but how would I use it within VBA to convert the 2 ranges
It depends what you want to do, do you want the value of the cell to be replaced by the true time/date?
 
Upvote 0
Heres a function you can use
VBA Code:
Function ConvDateTime()
    Dim cell As Range
    For Each cell In ThisWorkbook.Sheets("Sheet1").Range("H1:Q1").Cells
        cell.Value = TimeValue(cell.Value)
    Next cell
    For Each cell In ThisWorkbook.Sheets("Sheet1").Range("H3:Q3").Cells
        cell.Value = DateValue(cell.Value)
    Next cell
End Function
 
Upvote 0
Thanks

If I have it in a function, do I just call it from a sub
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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