+ Reply to Thread
Results 1 to 5 of 5

ForEach statement problem

Hybrid View

  1. #1
    excelnut1954
    Guest

    Re: ForEach statement problem

    Thanks for responding.....

    These are the other 2 subs that handle the Next and Previous buttons in
    UserForm13. When I have things set up (prior to trying the ForEach) ,
    everything worked ok. The user could hit Next over and over, same with
    the Previous button, and it would work fine.
    What I'm trying to do is to be able to show a number in TextBox16
    that will show which record the user is looking at. I already have
    TextBox15 which shows the total records found in the initial Find. That
    code is under the 2 subs. I wanted to assign a number to each record
    found. That number would show up in TextBox16. 1st record = 1, 2nd
    record = 2, etc.

    Whatever help you can offer, I would appreciate.
    Thanks,
    J.O.

    Sub TestFindNext_POCurrent()
    Worksheets("Official List").Activate
    Set rngFound = rngToSearch.FindNext(rngFound)
    rngFound.Select
    If rngFound.Address = strFirst Then
    MsgBox "There are no other records with this PO/PL."

    Else

    Unload UserForm13
    UserForm13.Show
    End If
    End Sub
    ********************************
    Sub TestFindPrevious_POCurrent()
    Worksheets("Official List").Activate
    Set rngFound = rngToSearch.FindPrevious(rngFound)
    rngFound.Select

    Unload UserForm13
    UserForm13.Show

    End Sub


    'Counter for how many of this PO/PL there are on the list
    'This goes in TextBox15
    CountPO = Application.CountIf(Range("J:J"), FindPOVal)
    TextBox15.Value = CountPO


  2. #2
    Dick Kusleika
    Guest

    Re: ForEach statement problem

    JO

    I think you will need to loop through the whole range and keep a count of
    the cells you find. Then when you get to the one whose Address property =
    rngFound.Address, you would stop counting and that would be the relative
    position of rngFound in the body of all cells that match your criteria. It
    seems like a lot of work, but I can't figure out how else you would know
    which it was in the list.

    You probably don't want to do a whole lot of rewriting, but I'll show you
    how I would do it. I would create a range of all the found cells and pass
    that into the userform. Then, I wouldn't close and reopen the userform,
    just use the FindNext and FindPrevious methods when the users clicks the
    buttons. Here's an example of what I mean

    http://www.dailydoseofexcel.com/arch...on-a-userform/

    --
    **** Kusleika
    MS MVP - Excel
    www.dailydoseofexcel.com

    excelnut1954 wrote:
    > Thanks for responding.....
    >
    > These are the other 2 subs that handle the Next and Previous buttons
    > in UserForm13. When I have things set up (prior to trying the
    > ForEach) , everything worked ok. The user could hit Next over and
    > over, same with the Previous button, and it would work fine.
    > What I'm trying to do is to be able to show a number in TextBox16
    > that will show which record the user is looking at. I already have
    > TextBox15 which shows the total records found in the initial Find.
    > That code is under the 2 subs. I wanted to assign a number to each
    > record found. That number would show up in TextBox16. 1st record = 1,
    > 2nd record = 2, etc.
    >
    > Whatever help you can offer, I would appreciate.
    > Thanks,
    > J.O.
    >
    > Sub TestFindNext_POCurrent()
    > Worksheets("Official List").Activate
    > Set rngFound = rngToSearch.FindNext(rngFound)
    > rngFound.Select
    > If rngFound.Address = strFirst Then
    > MsgBox "There are no other records with this PO/PL."
    >
    > Else
    >
    > Unload UserForm13
    > UserForm13.Show
    > End If
    > End Sub
    > ********************************
    > Sub TestFindPrevious_POCurrent()
    > Worksheets("Official List").Activate
    > Set rngFound = rngToSearch.FindPrevious(rngFound)
    > rngFound.Select
    >
    > Unload UserForm13
    > UserForm13.Show
    >
    > End Sub
    >
    >
    > 'Counter for how many of this PO/PL there are on the list
    > 'This goes in TextBox15
    > CountPO = Application.CountIf(Range("J:J"), FindPOVal)
    > TextBox15.Value = CountPO




  3. #3
    excelnut1954
    Guest

    Re: ForEach statement problem

    Thanks for getting back. I'll check this out this weekend. I just find
    it hard to believe that its impossible to just be able to assign a
    number, or a letter for that matter, to a record. You know... the 1st
    record found shall be named "X". and, X will = 1. The 2nd record found
    will be named "Y", and Y will = 2. So that when record X is shown, the
    textbox will show a 1. When record Y is shown, that textbox will show a
    2. That textbox would be next to the word "OF", and next to that will
    be the textbox that I already have that shows how many total records
    were found. 1 OF 2 2 OF 2

    I'll keep trying to learn more about memory, and maybe I'll stumble on
    it.
    I really appreciate your effort.
    Thanks,
    J.O.


+ 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