+ Reply to Thread
Results 1 to 12 of 12

Using a string to reverse fill Textboxes on a userform

  1. #1
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Using a string to reverse fill Textboxes on a userform

    Hi all,

    I have a two part question.

    I've got a VBA userform with 5 text boxes. When a user selects the cell the userform shows and I want the text boxes to fill each text box from a string in the cell which has a "-" as a seperator.

    E.g say the string was "Item 1 - Item 2 - Item 3 - Item 4 - Item 5"

    Userform1 Textbox1 would equal the string Item 1
    Userform1 Textbox2 would equal the string Item 2 etc

    The below works but wondered.

    1) Is there a better way to do this.
    2) How to count the number of "-" with using the Evaluate Method and a sumproduct formula which I'm doing at the moment


    Please Login or Register  to view this content.
    VBA Noob
    Last edited by VBA Noob; 04-27-2009 at 02:51 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using a string to reverse fill Textboxes on a userform

    Hello VBA Noob,

    I am not sure I understand what you want. The part about loading the TextBoxes is clear. The counting of "-" part is a bit unclear. Do you want to count all "-" within a range of cells?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Using a string to reverse fill Textboxes on a userform

    The counting of "-" part is a bit unclear. Do you want to count all "-" within a range of cells?
    Hi Leith,

    The string should contain 4 "-" in total so was really afer some way to build in validation of the string.

    I've managed to use the Evaluate Method and a sumproduct formula to validate the string but was wondering if there was a built in VBA function I've forgetten about\overlooked or a better way

    Hopefully it's a bit clearer.

    VBA Noob

  4. #4
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Smile Re: Using a string to reverse fill Textboxes on a userform

    Hello VBA Noob,

    I am new to this forum and you seem to be a pro. You possibly might know what I am trying to suggest in this post.

    To count the number of '-', you can use the 'UBOUND' function

    Please Login or Register  to view this content.
    Regards,
    Karan

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Using a string to reverse fill Textboxes on a userform

    Thanks karan but wanted to validate the string has 4 "-" before loading the userform Textboxes.

    e.g I'm replacing this

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    VBA Noob

  6. #6
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Re: Using a string to reverse fill Textboxes on a userform

    Dear VBA Noob,

    May be you can write something like this:
    Please Login or Register  to view this content.
    Or another way to do this would be to write something like this:
    Please Login or Register  to view this content.
    Regards,
    Karan

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using a string to reverse fill Textboxes on a userform

    Hello VBA Noob,

    This will validate that are at least 4 hyphens in the string. If you want to test for exactly 4 then it would require testing with RegExp.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Using a string to reverse fill Textboxes on a userform

    Thanks karan.

    Should of thought of doing that myself

    Please Login or Register  to view this content.
    Thanks again

    VBA Noob

  9. #9
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Smile Re: Using a string to reverse fill Textboxes on a userform

    Its a privilege to be of any help to you.

    Regards,
    Karan

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Using a string to reverse fill Textboxes on a userform

    Quote Originally Posted by Leith Ross View Post
    Hello VBA Noob,

    This will validate that are at least 4 hyphens in the string. If you want to test for exactly 4 then it would require testing with RegExp.
    Please Login or Register  to view this content.
    Thanks Leith. Works a treat as always.

    Thanks both for the help and input


    VBA Noob

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Using a string to reverse fill Textboxes on a userform

    Please Login or Register  to view this content.
    Last edited by shg; 04-27-2009 at 03:07 PM.
    Entia non sunt multiplicanda sine necessitate

  12. #12
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Using a string to reverse fill Textboxes on a userform

    Thanks shg for the input

    Better than my method

    Please Login or Register  to view this content.
    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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