formatting cell

rich_cirillo

Board Regular
Joined
Sep 26, 2012
Messages
247
Cell A2 has a start time and cell A3 has a finish time

Is there anyway of having a dropdown box in A2 and another dropdown box in A3 which has the current time displayed in 24hrs.....i just select the time in the dropdown box and it displayed the current time (in 24hr time) in the cell

Cheers

RC
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Do you need a drop-down with only one value? Could you just have the cells formatted as 24 hr time, select the relevant cell and then type Ctrl+Shift+:
 
Last edited:
Upvote 0
This will display & use the time at which you first select the cell in question, so by the time you have clicked the drop-down and selected the value it will be outdated. Whether that is an issue for you I don't know.

1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Select Case Selection.Address(0, 0)
    Case "A2", "A3"
       With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=Format(Now(), "hh:mm:ss")
    End With
  End Select
End Sub

It strikes me that a better option would be to have the person double click the cell to enter the current time. That could be done with this event code instead of the previous.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  Select Case Target.Address(0, 0)
    Case "A2", "A3"
      Cancel = True
      Target.Value = Format(Now(), "hh:mm:ss")
  End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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