+ Reply to Thread
Results 1 to 12 of 12

Userform, count selected characters

  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Userform, count selected characters

    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

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Userform, count selected characters

    Works for me:
    Please Login or Register  to view this content.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Userform, count selected characters

    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.

  4. #4
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform, count selected characters

    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.
    Attached Files Attached Files
    Last edited by Un-Do Re-Do; 09-30-2019 at 02:16 AM.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Userform, count selected characters

    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

  6. #6
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform, count selected characters

    Yes that's true. How could the selection be quantified?

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Userform, count selected characters

    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

  8. #8
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform, count selected characters

    Thanks for assisting. I'll keep working on it.

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Userform, count selected characters

    Didn't I just answer this in your other thread?
    Rory

  10. #10
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform, count selected characters

    Didn't I just answer this in your other thread?
    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.

  11. #11
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Userform, count selected characters

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    Best regards,

    Greg M

  12. #12
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Userform, count selected characters


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Weighted count of selected characters in a textbox
    By Un-Do Re-Do in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2018, 01:50 AM
  2. count number of characters between two characters
    By MrServer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-29-2017, 10:05 PM
  3. Replies: 7
    Last Post: 01-16-2017, 03:45 AM
  4. Replies: 2
    Last Post: 02-09-2016, 11:00 AM
  5. VBA Userform: Add selected userform value to selected any cell
    By nimesh29 in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 08-06-2014, 09:14 PM
  6. [SOLVED] Pass Value of combobox selected in Userform as input to textbox of other userform
    By Pradeepg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2013, 10:32 AM
  7. Display a UserForm based on Data selected in another UserForm's ListBox
    By RPhilbin83 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-26-2011, 11:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1