+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    12-09-2009
    Location
    ksa
    MS-Off Ver
    Excel 2007
    Posts
    25

    pick the number from a group

    dear all,
    my cell a1 = SOME 3 DIGIT numbers, b1 = 5678 my quistion is this how to pick the 5678 touching numbers in c1
    Attached Files Attached Files
    Last edited by teylyn; 12-15-2009 at 04:55 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007
    Posts
    6,259

    Re: how to pick the number from a group

    Could you edit the sample workbook, to show what the final results should be.

    Save it as a .xls, it would be easier for people without 'xl07 to down load
    Dave


  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: how to pick the number from a group

    Here's a UserDefinedFunction (UDF) you can add to your sheet to give the capability to do this:
    Code:
    Function StringTest(RNG As Range, RNG2 As Range)
    'JBeaucaire  (12/14/2009)
    Dim MyArr, MyArr2, buf As String, Chk  As Boolean
    Dim i As Long, j As Long, Cnt As Long
    
    MyArr = Split(Application.WorksheetFunction.Substitute(RNG.Value, Chr(10), "-"), "-")
    MyArr2 = Split(RNG2.Value, "-")
    
    For i = 0 To UBound(MyArr)
        For j = 0 To UBound(MyArr2)
            If InStr(MyArr(i), MyArr2(j)) Then Chk = True
        Next j
        If Chk Then
            buf = buf & MyArr(i) & "-"
            Cnt = Cnt + 4
        End If
        If Cnt = 40 Then
            buf = Left(buf, Len(buf) - 1) & Chr(10)
            Cnt = 0
        End If
        Chk = False
    Next i
    
    StringTest = buf
    
    End Function
    =========
    How to install the User Defined Function:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet as a macro-enabled workbook (.xlsm)

    The function is installed and ready to use.
    =============

    Now, based on your sample sheet, you enter this formula in C2:

    =STRINGTEST(A2, B2)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    12-09-2009
    Location
    ksa
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: how to pick the number from a group

    i dont know why this is not work with my sheet ????



    http://www.2shared.com/file/9989854/a00e4e93/Book1.html

  5. #5
    Registered User
    Join Date
    12-09-2009
    Location
    ksa
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: how to pick the number from a group

    i enter all the code and formula as you say
    but in c2 show #name#,
    what i do for this

  6. #6
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: how to pick the number from a group

    sun_ilkumar,

    please use the forum facilites to attach files. Linking to files on non-trusted external web sites is not the preferred option.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  7. #7
    Registered User
    Join Date
    12-09-2009
    Location
    ksa
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: how to pick the number from a group

    ok i attach my dummy sheet
    please check
    Attached Files Attached Files

  8. #8
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: how to pick the number from a group

    Your sample sheet does not match your sheet in post #1 at all. I've designed the UDF to fit your requirements from the posted sheet.

    Here is your original sheet in it with the UDF already installed.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  9. #9
    Registered User
    Join Date
    12-09-2009
    Location
    ksa
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: how to pick the number from a group

    ok, sir
    thank you for your hard work,
    i have one more doubt sir
    can i make all cell value in one cell,?
    example

    cell a1:j22 = 000-999
    how i put all theese number in one cell like cell L:27
    i attach the sheet with this
    thanks once again for your helping
    Attached Files Attached Files

  10. #10
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Cochrane,Alberta
    MS-Off Ver
    XL 2003,2007
    Posts
    6,259

    Re: how to pick the number from a group

    For what reason would you want to do such a thing?

    Anyway check out
    =CONCATENATE()
    Dave


  11. #11
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: how to pick the number from a group

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].



    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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.2.0