Delete text from text box

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a text box on my spreadsheet with some text in it, "Please type notes here", and when I click in it, I want the text to disappear. Is there a way to do this?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How do you close a thread?

Just commenting that the code provided works.

As I said, I am still glad to help you, but you could put feedback on each question solved.
 
Last edited:
Upvote 0
It does work but it is not really what I need as I didn't know what I needed when I asked the question. I need a text box that will expand down as you type more, but one that has default text "Please type text here" that will disappear when you click in it for the first time. The spreadsheet will also be locked and I will still want to be able to enter data in the text box. I think that is all I want.

Thanks,
 
Upvote 0
It does work but it is not really what I need as I didn't know what I needed when I asked the question. I need a text box that will expand down as you type more, but one that has default text "Please type text here" that will disappear when you click in it for the first time. The spreadsheet will also be locked and I will still want to be able to enter data in the text box. I think that is all I want.

Thanks,

Try this

Code:
Private Sub TextBox1_Change()
  TextBox1.Width = 200
End Sub


Private Sub TextBox1_GotFocus()
  TextBox1.Width = 200
  If TextBox1 = "Please type notes here" Then
    TextBox1 = ""
  End If
End Sub


Private Sub TextBox1_LostFocus()
  TextBox1.Width = 200
  If TextBox1 = "" Then
    TextBox1 = "Please type notes here"
  End If
End Sub

Change EnterKeyBehavior property to True
Change Multiline property to True
Change Autosize property to True
 
Upvote 0
I put the code of lostfocus() in the workbook open sub and it couldn't find the text box. It is an active x text box, is that the correct text box?
 
Upvote 0
I put the code of lostfocus() in the workbook open sub and it couldn't find the text box. It is an active x text box, is that the correct text box?


Before putting it on automatically, you tried what I sent you in post # 15.
As I told you, with all pleasure I continue to support you, but let's close one part and continue with another.
 
Upvote 0
I am sorry again that I keep asking different questions in this thread that are not relating to the title. I will try to remember to start a new thread and ask them for other threads.

Your code does in post 15 partially works, thank you.

It works when I have the file open and click in the text box but when I open the file, I get the error of object required and highlights this line
Code:
TextBox1.Width = 200
 
Last edited:
Upvote 0
But I have just realised that I don't need it as I have set the width in the properties so I opens the right width, meaning I could delete that code so it does work, thank you very much.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,877
Members
449,056
Latest member
ruhulaminappu

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