Empty textbox needs text

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a regular textbox (Shape, not an active x textbox) that needs to have the text "Please type notes here" if it doesn't have anything in it. I also need the text to disappear when you click in it so it is ready to type into. Could someone help me with the vba code please?
 
Did you change the name of the textbox in Kenneth code to your textbox name
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
As Ken has already said the flexibility to manipulate a simple textbox is limited
- the only event available "out of the box" is the click event
- which is OK if only want one event

But you need 2 events
- EVENT1 remove DefaultText & allow the UserText entry - Ken's click event code achieves that
- EVENT2 reinstate DefautText if box is empty when user is finished - this event cannot be easily captured

To "force" EVENT2 another trigger is required
- Ken's SelectionChange event code is triggered if any cell in the worksheet is clicked on
- if it does not work it is because you have made a mistake somewhere (eg code not in sheet module, incorrect textbox name etc ) or there is something else in your code causing the problem

SelectionChange is not triggered unless a cell is clicked on

Alternative
- consider using an active-x textbox because several triggers are available "out of the box"

Test in a NEW workbook by inserting an active-x textbox on sheet1 and putting this code in the SHEET module
Code:
Private Sub TextBox1_GotFocus()
    Application.ScreenUpdating = False
    TextBox1.Text = ""
End Sub

Private Sub TextBox1_LostFocus()
    If TextBox1.Text = "" Then TextBox1.Text = "Please type notes here"
End Sub
 
Last edited:
Upvote 0
Thanks for your responses guys. I first used an active x text box but I was having all kinds of problems with it, such as the speed of data entry was very slow, like having to wait at least a second until what you typed on the keyboard appeared, whenever I deleted all the contents, sometimes these grey boxes appeared inside the ends of the text boxes and if you clicked in the text box, they would disappear, only to reappear when I finished typing and when I did, you couldn't read what was behind them.

I think it was going really slow due to the code I already had that inserted please type notes here, when the box was empty and removed, in the change event for the box. This meant that every time a letter was typed, it would need to evaluate the code but I couldn't just have it in the got and lost focus events as I also needed the width of the box to stay at a fixed length.

I thought I would try a regular text box to see if I could avoid the problems, but it looks like the functionality of a regular box is not enough.
 
Upvote 0
I first used an active x text box but I was having all kinds of problems with it

That didn't seem to work

I am trying another way

When I click on the box in your file I get the error Invalid procedure call or argument


Perhaps the problem is in your current workbook (minor corruption ? memory issue ? problem in your existing code ?)

Ken's suggestions work perfectly well and you should be able to get them to work
- create a new workbook, try those suggestions and tell us how you got on

You did not answer Ken's question - which version of Excel are you using? which operating system ?
 
Upvote 0
You did not answer Ken's question - which version of Excel are you using? which operating system ?

I forgot to, sorry. I am using win 10 and microsoft office professional plus 2016.
 
Upvote 0
Ken's suggestions work with your set-up
Try them in a new workbook
 
Upvote 0
As commented earlier, don't forget to change the shape name, Rectangle 1, to your shape's name if that was not used.
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,594
Members
452,656
Latest member
earth

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