Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 4 of 4

Thread: Split Cell With Hyphen Into Two Textboxes

  1. #1
    Join Date
    8th December 2006
    Location
    New Zealand
    Posts
    3,894

    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.

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    22nd January 2004
    Location
    Colorado Springs
    Posts
    3,741

    Re: Split Cell With Hyphen Into Two Textboxes

    reafidy,


    VB:
    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. #3
    Join Date
    8th December 2006
    Location
    Guildford, UK
    Posts
    242

    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"

    VB:
    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 at 07:22.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    8th December 2006
    Location
    New Zealand
    Posts
    3,894

    Re: Split Cell With Hyphen Into Two Textboxes

    Perfect, big thanks to you.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Remove Hyphen & Split Cell Contents
    By Miami99 in forum EXCEL HELP
    Replies: 5
    Last Post: February 1st, 2008, 10:10
  2. Format Textboxes According To Cell Values
    By tochybaja in forum EXCEL HELP
    Replies: 2
    Last Post: August 21st, 2007, 19:39
  3. Replies: 9
    Last Post: August 1st, 2006, 13:56
  4. Replies: 1
    Last Post: January 26th, 2006, 23:51
  5. Hyphen in Cells Meeting a Criteria
    By Terryleaman in forum EXCEL HELP
    Replies: 12
    Last Post: December 23rd, 2005, 17:54

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
  •  
porno