VBA - Modify Cell Date to remove Time Value

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi guys,

I have some dates in the format:

dd/mm/yy hh:mm

with some other dates in the format:

dd/mm/yy.

The ones in the format dd/mm/yy hh:mm are severly messing up my vlookups (despite leaving the last argument absent, or as false). Ideally, when the data is imported I would like my VBA to remove the time stamp completely, leaving the date just as dd/mm/yy.

Does anyone know how to accomplish this?

Thanks all
 
Or maybe

Code:
Sub ToDate()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    With Range("A" & i)
        .NumberFormat = "dd/mm/yy"
        .Value = Int(.Value)
    End With
Next i
End Sub
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
There are currently 31 rows, but yes there is several vlookups that reference the dates, that must be the reason, it must be recalculating the cells after each date is updated. I'll try populating the dates before filling in the vlookups.

Cheers
 
Upvote 0
Try

Code:
Sub ToDate()
Dim LR As Long, i As Long
Application.Calculation = xlCalculationManual
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    With Range("A" & i)
        .NumberFormat = "dd/mm/yy"
        .Value = Int(.Value)
    End With
Next i
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
Thanks for all the help both of you, finally working correctly now :)

Edit: Didn't see your latest post until now VoG, out of curiosity, what does that last line do? Stall the calculations?
 
Upvote 0
I would use

Code:
If IsDate(testDate) = True Then
testDate = Format(testDate, "dd/mm/yyy")
testDate = CDate(testDate)
End If

As I feel it is more elegant
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,218
Members
453,152
Latest member
ChrisMd

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