Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2021, 06:57 AM
Chocolate Chocolate is offline Find&Replace multiple words in userform TextBox Windows 10 Find&Replace multiple words in userform TextBox Office 2016
Novice
Find&Replace multiple words in userform TextBox
 
Join Date: Dec 2021
Posts: 1
Chocolate is on a distinguished road
Default Find&Replace multiple words in userform TextBox

Hello.



I have been trying to find some solution or workaround to this, but surprisingly (and annoyingly) it doesn't seem like anything I've found online can be used for my situation.

I have a userform where there is a TextBox, let's say "TextBox01". In it, the user would input a series of numbers, and each number would always refer to certain words. For example, number "01" would refer to "broken left arm", "02" would refer to "broken right arm", and so on. With plenty of bones to break, the list is quite long, sitting at about 50 possible numbers, each of which would have to be then "converted" (via find-and-replace or any similar method) into words.

The "converted" (replaced) text would then appear into TextBox02, and then further processed to eventually be inserted into a bookmark, Bookmark01.

I initially had success using this formula into TextBox01:
Me.TextBox02 = Replace(Me.TextBox01, "01", "broken left arm")

I was baffled to find out that one of these is just about all the program can handle. If I place two of them, only the second one will be applied (only the second number will be found-and-replaced); if I place three or more the program will crash as soon as I type the third number.

Anyway, I've searched on google for hours and found lots of similar cases, but never one where they do this exact thing. Sometimes the code is for Excel (like, 80% of the time), sometimes it's for the whole document, sometimes it's for TextBoxes in the document but not for TextBoxes in the userform, ... "Frustrating" doesn't even begin to describe my experience with it, as this seems like an extremely simple thing to do, and yet it seems there is no easy function where you can just make a list of all the replacements you need. The way the program crashed was particularly infuriating, as I'm sure something as simple as finding and replacing text cannot require so much "power" that three requests at once would blow up a whole code. Before this I had tried writing a few hundreds of "if -> then" statements to manually replace the text that way, and THAT worked instantly without a hiccup. Like the infomercials say though, there has to be a better way.
Reply With Quote
  #2  
Old 12-31-2021, 02:37 AM
gmayor's Avatar
gmayor gmayor is offline Find&Replace multiple words in userform TextBox Windows 10 Find&Replace multiple words in userform TextBox Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Why are you even using a userform text box for this? Surely a combobox would make more sense? You could then have two columns in the list box, one for the number, the other for the description. You can choose whether or not to display the second column, if the users know what the numbers refer to. If you have the list in Excel, you can read the values into the listbox. See example attached. Save both items in the same folder for the list to work.
I also suggest using content controls rather than bookmarks as they are much less likely to be accidentally deleted. see
https://www.gmayor.com/insert_content_control_addin.htm
Attached Files
File Type: docm Example.docm (38.9 KB, 10 views)
File Type: xlsx List.xlsx (7.9 KB, 10 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find&Replace multiple words in userform TextBox Find and replace words according to excel file laith93 Word VBA 7 12-13-2021 08:11 PM
Userform textbox control missing/invisible; can't find, use or replace it; how to salvage work on a marceepoo Word VBA 8 05-01-2020 09:56 PM
Find&Replace multiple words in userform TextBox Find & Replace Multiple words Gartholameau Word VBA 2 01-20-2019 04:56 PM
Find&Replace multiple words in userform TextBox multiple find and replace in vba for special words kvnrao Word VBA 7 11-02-2018 06:28 PM
Find&Replace multiple words in userform TextBox Find and replace mutiple spaces between lowercase words only Dave T Word VBA 2 07-16-2015 11:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft