Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


How to find and replace specific text in text boxes?

Find and Replace is a useful tool for us to find and replace cell contents or formulas quickly and conveniently in a worksheet. But now, I have multiple text boxes in my worksheet, and I want to find the specific text and replace it with other value in these text boxes only. Do you have any good ways to deal with this problem?

Find and replace specific text in multiple text boxes

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately. 60-day Unlimited Free Trial

arrow blue right bubble Find and replace specific text in multiple text boxes

You can find and replace the text that you need manually one by one, but if there are multiple text boxes, this will be boring and tired. So the following VBA code can help you finish it at once.

1. Activate your worksheet, and hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Find and replace specific text in text boxes of current worksheet

Sub TextBoxReplace()
Dim xWs As Worksheet
Dim shp As Shape
Dim xFindStr As String
Dim xReplace As String
xFindStr = Application.InputBox("Find:", xTitleId, "", Type:=2)
xReplace = Application.InputBox("Replace:", xTitleId, "", Type:=2)
Set xWs = Application.ActiveSheet
On Error Resume Next
For Each shp In xWs.Shapes
    xValue = shp.TextFrame.Characters.Text
    shp.TextFrame.Characters.Text = VBA.Replace(xValue, xFindStr, xReplace, 1)
End Sub

3. Then press F5 key to run this code, and a prompt box will pop out to remind you entering your old text that you want to replace. See screenshot:


4. Go on clicking OK, and in this  prompt box, type the new text value that you want, see screenshot:


5. And then click OK button, the old values have been replaced with the new values that you entered in the current worksheet. See screenshots:


Related articles:

How to find and replace text in chart titles in Excel?

How to find and replace text within comments in Excel?

How to change multiple hyperlink paths at once in Excel?

Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for you.

  • Designed for 1500+ work scenarios, helps you solve 80% Excel problems.
  • Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  • Being used by 110,000 elites and 300+ well-known companies.

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jeremy · 11 days ago
    Great, thanks! This was VERY handy to adapt for my specific use.
  • To post as a guest, your comment is unpublished.
    Jeremy · 11 days ago
    Great, thanks! This was VERY handy to adapt for my specific use.
  • To post as a guest, your comment is unpublished.
    Carlos · 2 months ago
    How can I do the same in Kutool for Word
  • To post as a guest, your comment is unpublished.
    Aliya · 8 months ago
    I am still not sure how to do find and replaced, to know how to use the VBA codes needs to be more clear
  • To post as a guest, your comment is unpublished.
    Yaseen · 1 years ago
    Hello, it works great on a single sheet. I wanted to know how can I have this work for the workbook having multiple sheets. Thanks