Is there a way to count the number of characters highlighted in a userform textbox.
Have tried the following but it gives a value of "0" instead of "4".
Please Login or Register to view this content.
Capture.PNG
Is there a way to count the number of characters highlighted in a userform textbox.
Have tried the following but it gives a value of "0" instead of "4".
Please Login or Register to view this content.
Capture.PNG
Works for me:
Please Login or Register to view this content.
If you want to do it your way you should have something like
Please Login or Register to view this content.
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
It's still not working.
The background ... the callup comes from a userform change event, which is when you highlight part of the string and then type anything on the keyboard. "Sub transfer()" is supposed to occur when you type something.
The full workbook is attached.
It may be that the event is lost since the sub runs on the keystroke.
Please Login or Register to view this content.
Last edited by Un-Do Re-Do; 09-30-2019 at 02:16 AM.
Hi there,
New text typed into the TextBox will appear there, but will NOT be selected, so (it seems to me ) this is the reason why the .SelLength property returns a value of zero rather than the number of new characters entered.
Regards,
Greg M
Yes that's true. How could the selection be quantified?
Hi again,
I think that this could be tricky!
You could probably use a "Previous Text" vs "New Text" approach to highlight either a single typed character or a group of pasted characters, BUT (and this might be where the whole thing could fall down!) if one or more characters are selected, a subsequent typing or pasting operation will REPLACE the selected character(s), so you'd need to keep continually updating the value of the "Previous Text" variable, comparing that value with the "New Text" value and determining which characters need to be highlighted.
If characters can be DELETED from the TextBox it will probably add another layer of complexity to the process.
I'm not saying it's impossible, just that it's probably one of those things that turn out to be more complicated than appeared at first sight.
Regards,
Greg M
Thanks for assisting. I'll keep working on it.
Didn't I just answer this in your other thread?
Rory
Hi, yes you did answer the question in that post but I haven't gotten to the end yet. I may or may not end up using that solution.Didn't I just answer this in your other thread?
Hi again,
Many thanks for your feedback and also for the Reputation increase - much appreciated!
Best regards,
Greg M
See this thread for solution.
https://www.excelforum.com/excel-pro...ml#post5202749
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks