vba lock text in a textbox

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Is it possible to input some text into a textbox and prevent the user from deleting it, but still allow the user to input text of their own.

For instance, what I want to do is have a text box which asks the amount of hours lost.

I want this to be shown like 53 hrs 25 mins.

So ideally I would like the hrs and mins to already be in the textbox, and to limit the user to only input number values. I can do all this, but I don't know how to prevent the user from deleting the "hrs" or "mins" from the text.

Any ideas?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Perhaps something like this:-
Code:
Private Sub TextBox1_LostFocus()
Dim txt As String
txt = "    hh :    mm  "
    If Not Len(TextBox1) > Len(txt) Then
        TextBox1.Text = txt
    End If
End Sub
 
Upvote 0
Yes Stefan, that's what I have now done.

Thanks MickG, I will make a note of that for when I need it in the future.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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