+ Reply to Thread
Results 1 to 11 of 11

Findnext method

Hybrid View

  1. #1
    Registered User
    Join Date
    02-28-2004
    Location
    Oregon
    Posts
    35
    Hi,


    This FindNext method works for me ...


    Option Explicit
    
    Sub Test1()
        Dim ptipn As String, r1 As Range, r2 As Range, r3 As Range
        Dim response As VbMsgBoxResult, r1Addy As String
    Start:
        ptipn = InputBox("Enter PTI Part number:", "Lookup Value")
        If ptipn = vbNullString Then Exit Sub
        Set r1 = Range("B:B")
        Set r2 = r1.Find(ptipn)
        If r2 Is Nothing Then
            response = MsgBox("The Part number " & _
            ptipn & " was not found. Would you like to try again?", vbQuestion + vbYesNo)
            If response = vbYes Then
                GoTo Start
            ElseIf response = vbNo Then
                End
            End If
        Else
            r1Addy = r2.Address
            Set r3 = r2
            Do
                Set r2 = r1.FindNext(r2)
                Set r3 = Union(r3, r2)
            Loop Until r2.Address = r1Addy
        End If
        If Not r3 Is Nothing Then
            'do something with those found here
            r3.Select
        End If
    End Sub

    HTH
    Regards,
    Zack Barresse

  2. #2
    Registered User
    Join Date
    12-10-2004
    Posts
    40

    il give it a try...

    thanks fire..ill give it a try. Man urs is soo much more concise..i feel dumb :/

    but my first code ever written..so heh..

  3. #3
    Registered User
    Join Date
    12-10-2004
    Posts
    40

    ok i did some modifications..

    it works..but how do i get the last found part...store the address and compare it to the first initial value..and if its the same...a msgbox displaying "no more matching parts.....want to continue back to the beginning? yes / no?"

  4. #4
    Registered User
    Join Date
    02-28-2004
    Location
    Oregon
    Posts
    35
    Yeah, and that's basically how the above works. It will compare the first address it comes across and when the Loop comes back to the starting point (that first address) it will exit the Loop. I guess you could ask to start again, but it would be redundant, as you would have just performed the same commands. So I don't understand the why, but in essence yes, add it right after the loop.

    And glad it works for you. You should have seen my first code!! Oh, was it ugly! LOL!

  5. #5
    Registered User
    Join Date
    12-10-2004
    Posts
    40

    fire..thanks...

    i got another question for u...

    i dont know how to call my procedure..

    in sheet one..i have Sub Testfile1() and sheet2 i have Sub Testfile2().

    Then in the Private Sub Workbook_Open()

    i put

    Private Sub Workbook_Open()

    TestFile1
    TestFile2
    If Weekday(Now) = vbFriday Then
    ThisWorkbook.SaveCopyAs "H:\600 series PB free" & ThisWorkbook.Name
    End If


    End Sub

    It keeps giving me an error that i havent defined sub or procedure. I went to tools >> references but it was dim..so i couldnt select it. I tried to use the CALL Testfile1 and Testfile 2. Same problem. Whats the problem? Please advise

  6. #6
    Registered User
    Join Date
    02-28-2004
    Location
    Oregon
    Posts
    35
    Right off hand, I'd say take your two Sub routines (Testfile1 and Testfile2) and put them into a Standard Module ( Insert | Module ), not in a worksheet module. And without seeing your Testfile1 and/or Testfile2 routines, I'm not sure what else it may be. But definitely put them into a standard module first.

    Also, is that your entire filename? You are appending prior to the name, saving to H? Which I'm assuming is a network drive.. ? If that is the directory, don't forget your last backslash.

  7. #7
    Registered User
    Join Date
    12-10-2004
    Posts
    40

    thanks for teh advise on the file name...

    im kinda confused with modules vs procedures...


    http://www.excelforum.com/newreply.p...ote=1&p=869479

    check it out...

    does my reasoning make sense??

    well what i said in that one was....if i put testfile1 and testfile2 into the individual sheets for code...why should it need to be placed into the module. It would only make sense if i was altering the workbook 'overall'. Since im only throwing data into the respective sheets. All i want is to load both the routines....

    i ask this because if i ever decide to make a bigger program...i dont awnna copy loads of routines into modules....

    can u give me an example as to when u would EVER use whats in the sheets procedures??

    sorry.....im still in college...heh..

+ 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