Date/Time Value not being stored as Date/Time?

Pascal

Board Regular
Joined
Jun 6, 2007
Messages
200
Hi,

I have the following code from my Form which stores the Date & Time of an entry on to my sheet: -

Code:
Private Sub BookVehicle()

    Dim lngLast As Long
    
    '* Find Last Row.
    lngLast = Range("B65536").End(xlUp).Row + 1
    
    '* Select row.
    Cells(lngLast, 4).Select
     
    '* Add (Append) Entry to Sheet.
    With frmAdd
        Cells(lngLast, 2).Value = UCase(.cboRegistrations.Value)
        Cells(lngLast, 3).Value = UCase(.txtContractor.Text)
        Cells(lngLast, 4).Value = ActiveCell.Row - 10
        Cells(lngLast, 5).Value = UCase(.txtNo.Text)
        Cells(lngLast, 6).Value = UCase(.cboContact.Value)
        Cells(lngLast, 7).Value = UCase(.txtLocation.Text)
        Cells(lngLast, 8).Value = Format(Date, "dd/mm/yyyy") & "  " & Format(.dtpTimeIn.Value, "hh:mm:ss")
        Cells(lngLast, 9).Value = Format(.dtpTimeIn.Value, "hh:mm")
        '* If Phone field left blank treat as no Phone given.
        If .txtPigeon.Text = "" Then
            Cells(lngLast, 11).Value = "X"
        Else
            Cells(lngLast, 11).Value = .txtPigeon.Text
        End If
    End With
    
    Cells(lngLast, 9).NumberFormat = "hh:mm"
    
    '* Format entry.
    With Range(Cells(lngLast, 2), Cells(lngLast, 12))
        .Font.Name = "Tahoma"
        .Font.Size = 12
        .VerticalAlignment = xlCenter
    End With
    
    Range(Cells(lngLast, 4), Cells(lngLast, 5)).HorizontalAlignment = xlCenter
    Range(Cells(lngLast, 9), Cells(lngLast, 11)).HorizontalAlignment = xlCenter
    
    'Range(Cells(lngLast, 8), Cells(lngLast, 8)).NumberFormat = "dd/mm/yyyy hh:mm"
    
End Sub

After carrying out some bookings this is the data that has been stored: -


Excel 2010
BCDEFGHIJKL
10RegistrationContractorNo.No. of PersonsContactLocationTime InTime OutPhoneNotes
11HK57 LFLTSML11L REYNOLDSSITE15/08/2013 19:42:0019:42X
12RK56 XFBTSML21L REYNOLDSSITE15/08/2013 19:48:0019:481
13B11 VVYBLUE SHIELD32L BARTLETTENGINEERS15/08/2013 19:48:0019:482
14WV11 DXEANDY WATERS41G WILLIAMSSITE15/08/2013 19:49:0019:493
Home


In column H it shows the Date & Time, however it's Left Aligned. Only if I select the cell, hit F2 and then enter does it Align it to the Right and is picked up correctly in my formulas, such as: -

Code:
=COUNTIFS(H11:H50,">"&O2,H11:H50,"<="&O3)

Below I've carried out the F2 & Enter on the last two rows to show you what I mean: -


Excel 2010
BCDEFGHIJKL
11HK57 LFLTSML11L REYNOLDSSITE15/08/2013 19:42:0019:42X
12RK56 XFBTSML21L REYNOLDSSITE15/08/2013 19:48:0019:481
13B11 VVYBLUE SHIELD32L BARTLETTENGINEERS15/08/2013 19:4819:482
14WV11 DXEANDY WATERS41G WILLIAMSSITE15/08/2013 19:4919:493
Home


What can I do to correct this via my code?

Many Thanks & Regards
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This line

Cells(lngLast, 8).Value = Format(Date, "dd/mm/yyyy") & " " & Format(.dtpTimeIn.Value, "hh:mm:ss")
Is entering a TEXT string (the Format function returns TEXT)

Try changing that to just simply
Cells(lngLast, 8).Value = Date + .dtpTimeIn.Value
 
Upvote 0
This line

Cells(lngLast, 8).Value = Format(Date, "dd/mm/yyyy") & " " & Format(.dtpTimeIn.Value, "hh:mm:ss")
Is entering a TEXT string (the Format function returns TEXT)

Try changing that to just simply
Cells(lngLast, 8).Value = Date + .dtpTimeIn.Value

:) LOL

Many, many thanks for your time in replying!

I'd tried all sort of combinations apart from that, which worked.

Once again, thank you.

Regards
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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