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

    exel formula for sorting digits

    dear grand masters
    i have one more doubt about the follwing

    cell a1 is some digits
    cell b1 my cutting digits
    cell c1 result

    i don''t want the cell b1 digits in my result(cell c1)
    only the balance number from cell a1 is in cell c1
    any one help
    thank you for all of your great support
    Attached Files Attached Files
    Last edited by sun_ilkumar; 12-15-2009 at 04:23 PM.

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

    Re: exel formula for soarting digits

    In your other thread here:
    http://www.excelforum.com/excel-new-...m-a-group.html

    You asked the same question and I provided a UDF that is ready to go and works.

    For your workbook above, put the dashes BACK in B1 so that it reads 2-4-6-7 and the UDF which you were already given will continue to work for you.

    I'm hoping your next question is not a variation of the same thing again.
    _________________
    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!)

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

    Re: exel formula for sorting digits

    sir
    both are different books
    first book is ok and working perfectly,
    but the second case is enterly different from the first one
    both i attached with this one
    the difference is the result
    first one i need that numbers in the result
    second one i don't want that numbers in result
    hope you understand me
    Attached Files Attached Files

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

    Re: exel formula for sorting digits

    Let's use the same UDF for both functions. Here's the code:
    Code:
    Option Explicit
    
    Function STRINGTEST(RNG As Range, RNG2 As Range, Excl As Boolean)
    'JBeaucaire  (12/15/2009)
    Dim MyArr, MyArr2, buf As String, Fnd 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
                Fnd = True
                Exit For
            End If
        Next j
        If (Fnd And Not Excl) Or (Not Fnd And Excl) 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
        Fnd = False
    Next i
    
    Do
        If Right(buf, 1) = "-" Then
            buf = Left(buf, Len(buf) - 1)
        Else
            STRINGTEST = buf
            Exit Do
        End If
    Loop
    
    End Function
    I've added a third parameter, it is now used like so:

    =STRINGTEST(A2, B2, FALSE)

    First parameter is the cell with the - separated values to test
    Second parameter is the cell with the - separated digits to include/exclude
    Third parameter is FALSE to include the digits in the second parameter, is TRUE to exclude them.
    Last edited by JBeaucaire; 12-15-2009 at 04:07 PM. Reason: Major bug fixed. Should work now.
    _________________
    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!)

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

    Re: exel formula for sorting digits

    thank you big boss

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

    Re: exel formula for sorting digits

    Code above has had a major bug fixed in the logic. It should work now.

    =========
    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.)
    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!)

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