Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Split Cell With Hyphen Into Two Textboxes

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Split Cell With Hyphen Into Two Textboxes

    Hi Everyone.

    I have a cell containing a hyphen with data like cars - buses.

    I have a userform set up with 2 text boxes. What I would like to do is when loading the userform put the information from the cell before the hyphen in one textbox and the information after the hyhen in another text box. ie one textbox would have cars the other textbox would have buses.

    Anyhelp much appreciated.
    Reafidy

    Forum Rules | Anatomy Of A Good Thread Title | What Have You Tried So Far? | Are You A Cross Poster?

  • #2
    Re: Split Cell With Hyphen Into Two Textboxes

    reafidy,


    Code:
    strValue = "cars - buses"
    TextBox1 = split(strValue," - ")(0)
    TextBox2 = split(strValue," - ")(1)
    Regards,
    Barry

    My Favorite New Thing:
    Dynamic Named Ranges



    The alternative for
    "Press Any Key To Continue."

    and we all have one we'd like to use it on

    1. Cross Posting Etiquette
    2. Are You Here To Learn: What Have You Tried?
    3. Your Best Resource to begin learning VBA: RECORD A MACRO . . . Then Study It!

    Comment


    • #3
      Re: Split Cell With Hyphen Into Two Textboxes

      iwrk4dedpr got there before me; and much more elegantly!

      You might also consider using Trim() to trim any leading or trailing spaces. Also, although VBA allows you to write "TextBox1 = xxx", it is technically correct to write "TextBox1.Value = xxx"

      Code:
      Option Explicit
      
      Private Sub UserForm_Activate()
           Dim StrValue As String
      
           StrValue = "   cars  -   buses    "
           TextBox1.Value = Trim(Split(StrValue, " - ")(0))
           TextBox2.Value = Trim(Split(StrValue, " - ")(1))
      
      End Sub
      Last edited by Arthur494; January 10th, 2007, 08:22.

      Comment


      • #4
        Re: Split Cell With Hyphen Into Two Textboxes

        Perfect, big thanks to you.
        Reafidy

        Forum Rules | Anatomy Of A Good Thread Title | What Have You Tried So Far? | Are You A Cross Poster?

        Comment

        Trending

        Collapse

        There are no results that meet this criteria.

        Working...
        X