VBA within excel, Setting time so that the : isn't editable.

PetSlug

New Member
Joined
Sep 11, 2014
Messages
2
Good Morning!

I have what might seem to be a simple question to most but I feel like Pinky off Pinky and the Brain...

So here it is... "I have the following code for a textbox within my excel.
Code:
Private Sub TextBox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

Select Case KeyAscii

    Case 48 To 57 'For Numbers 0 to 9

    Case 58 'For : as it's time I was selected in my box!
       If InStr(ActiveControl, ":") Then KeyAscii = 0

    Case Else
       KeyAscii = False
End Select

End Sub
In the user form part of the tool I have it so that it picks up the time on my desktop so people have some what of an idea what to put in :cool: which is working kind of how I would like it... I would like to get it so when people edit the time so that it's almost exactly when the event happened they are only able to edit the HH and the MM but the : Between the HH:MM < Like that is not able to be erased.

Is this possible?

Thanks,
John.
 
Last edited by a moderator:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
John,

Welcome to MrExcel.

I'm not convinced that you can avoid the user editing the colon in that way.

Here is a link to a small example file where I have used two independent text boxes, one for hours input and one for minutes in order to capture a time in a way that might suit you.

https://www.dropbox.com/s/r5pew0enwm7p6lv/Time_Input.xlsm?dl=0


Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

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