+ Reply to Thread
Results 1 to 5 of 5

Thread: .Find problem when the found range's rows go from single to double digits

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    6

    .Find problem when the found range's rows go from single to double digits

    Hi, I am having a little issue with my code.

    Code:

    Private Sub cbx3_Change()
    
        cbx4.Clear
        cbx4.Text = "Select Material"
        
        Dim cbx3rng As Range, firstfound As String
                  
         With Worksheets(1).Columns(1)
         
         Set cbx3rng = .Find(cbx3.Value, Range("A1"), MatchCase:=False)
             
         If Not cbx3rng Is Nothing Then
            firstfound = cbx3rng.Address
            cbx4.AddItem cbx3rng.Offset(0, 1).Value
            Do
            Set cbx3rng = .FindNext(cbx3rng)
            cbx4.AddItem cbx3rng.Offset(0, 1).Value
            Loop Until cbx3rng.Address <= firstfound Or cbx3rng Is Nothing
         End If
         End With
    
    End Sub
    cbx3 and cbx4 are comboboxes, cbx4 is populated from the selection made in cbx3.

    My table, basically, is a list of parts (from 1 to 17) that have different materials associated with them. Part1 has 15 materials, part2 has 10, etc.




    The issue is that when my Find arrives at Cell "A10", it stops and returns the value of A10 as the last cell of the find, but in my table it should go up to A15.

    Changing the Range in red to Range("A10") solves this issue.

    Going from single digit to double digit seems like the problem.

    Also, the same thing happens for a search where the cells in column A containing cbx4.Value are between 90 and 110, the search stop at 100. It seems that going from double digits to triple digits also makes an error.

    Changing the Range in red to Range("A100") solves this issue, but not the first one (going from single to double digits).

    Anyone has any experience with this problem ?

    Thanks,
    Alexis
    Last edited by alsega; 02-13-2012 at 10:50 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    3,788

    Re: .Find problem when the found range's rows go from single to double digits

    I think you need to close your loop with
    Loop while cbx3rng.Address <> firstfound

  3. #3
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: .Find problem when the found range's rows go from single to double digits

    Change this:
    Loop Until cbx3rng.Address <= firstfound Or cbx3rng Is Nothing
    to this
    Loop While cbx3rng.Address <> firstfound
    Good luck.

  4. #4
    Registered User
    Join Date
    02-13-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: .Find problem when the found range's rows go from single to double digits

    Hi guys, thanks for the quit answers.

    Loop while cbx3rng.Address <> firstfound


    That does work like a charm ! Simple solutions always work the best.

    Thanks alot!
    Alexis

  5. #5
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: .Find problem when the found range's rows go from single to double digits

    Please don't forget to mark the thread solved.
    Good luck.

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