Trim date from date/time

BubbaBBQ

Board Regular
Joined
Jan 29, 2003
Messages
68
I have columns of cells that list date and time. Each cell looks like this:

3/17/2006 3:30:00 PM

I need VBA to loop through and remove the time and leave just the date. When finished it will look like this:

3/17/2006

A simple left trim doesn't work because of varied lengths of month, date, and time. The For Next loop isn't the problem, but I can't figure out what to do to trim the time.

I have tried:

Code:
    vCdate = Cells(sRow, 5).Value
    vTrimDate = Left(vCdate, Find(" ", vCdate) - 1)
    Cells(sRow, 5).Value = vTrimDate

This doesn't work. I don't think "Find" is a valid VBA term.

Any suggestions will be appreciated.

Bubba
 
Hie to you all,

Supposing your date are in column("E") if not change E to your column letter.

then run this code:

Sub removetime()
For Each ran In Columns("e").Cells
If VarType(ran) = vbDate Then
ran.Value = Int(ran)
ElseIf VarType(ran) = vbString Then
ran.Value = Int(DateValue(ran))
End If
Next
Set ran = Nothing
End Sub

This seems to give me the most hope. The results are converting the time to 0:00. Hopefully, this will give us consistant results in the pivot tables. We'll give a try.

Thanks for the suggest.

Bubba
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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