+ Reply to Thread
Results 1 to 5 of 5

Copy everything before number start

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-12-2009
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    219

    Copy everything before number start

    Hi

    I have a list of label in a drop down menu like this:
    MACY 147458 - ATLANTA
    Hardware Electronic 149867 - GREAT
    Visual Basic 0445542 - STRUCTURE

    If I select “MACY 147458 – ATLANTA”, I want the cell in “B1” just spit out MACY. If I select “Hardware Electronic 149867 – GREAT”, I want cell B1 just spit out Hardware Electronic. Basically to copy everything before the number started to cell “B1”.

    Thank you
    VBisgreat
    Last edited by VBisgreat; 04-05-2011 at 05:20 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Copy everything before number start

    Assuming the control is a ActiveX control placed on the spreadsheet and not on a userform, you'd have to use something like this:

    Private Sub ComboBox1_Change()
    
    Dim str As String
    
    str = Me.ComboBox1.Value
    
    For i = 1 To Len(str)
        If IsNumeric(Mid(str, i, 1)) = True Then
            Cells(1, 2).Value = Mid(str, 1, i - 1)
            Exit Sub
        End If
    Next i
    
    
    End Sub
    Let me know if you have any questions.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Contributor
    Join Date
    05-12-2009
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    219

    Re: Copy everything before number start

    Is there a formular for this? Thanks a lot. I know the =left() formular but I don't want to keep adjust the formular everytime, I want to automate this so everytime I select another lable it just spit out the name of the lable before the number begin in another cell. Thanks!
    Last edited by VBisgreat; 04-05-2011 at 05:34 PM.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Copy everything before number start

    Hi VBisgreat,

    Based in part from Domenis's post from here, try this (just change the cell reference from A6 to suit):

    =TRIM(LEFT(A6,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A6&" 0123456789"))-1))

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Contributor
    Join Date
    05-12-2009
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    219

    Re: Copy everything before number start

    Thank you all: davegugg and davegugg

+ 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