+ Reply to Thread
Results 1 to 3 of 3

problem with for and next loops

  1. #1
    Registered User
    Join Date
    11-28-2003
    Posts
    39

    problem with for and next loops

    I am getting duplicate results from the following for and next loop.

    There are 2 loops - i think the "i" loop is giving the duplicate results.
    Could smebody help me to resolve this duplication so that i end up with only one set of results. Thanks

    With UserForm1
    .ListBox2.RowSource = ""
    .ListBox2.ColumnCount = 2
    .ListBox2.Clear
    End With
    Dim jo As Integer
    Dim Mee As Integer
    Dim u As Integer
    Dim i As Integer
    jo = UserForm1.IDsearch.Value
    For i = 3 To 10
    For Mee = 25 To 32
    Set y5 = (ActiveSheet.Cells(5, i))
    Set y6 = (ActiveSheet.Cells(jo, Mee))
    With ListBox2
    .AddItem y5.Value
    .List(u, 1) = y6
    u = u + 1
    End With
    Next Mee
    Next i
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Mike,

    After looking at your code, I am still not certain what you want to do with the list box. My assumption is your are trying to load columns. Tell me what you want to do, and I will help you with this code.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    11-28-2003
    Posts
    39
    Cheers leith,

    You're right i am trying to fill listbox2.

    i'll try and explain.
    On sheet one between y1 and Af100 i have data(all numeric) which needs copied to column two of listbox2 based on the value of jo (idsearch) from column X.

    Each row of data data is numbered numerically in column X (in order from 1 to whatever). The value of jo selects which row to copy. For example is jo = 5, then row 5 is copied. (that is y5 to af5).

    NEXT

    I have text to be filled in column 1 of listbox2
    this data is in celles c5 to j5. this text never changes.
    The text is C5:"Hats 1", C6:"Hats 2", and so on...
    perhaps this can just be inserted in column one as an array or something??

    In the end i need two columns, col 1: Hats 1 to Hats 8. and col2: with correct row of data selected by jo (idsreach)

    i hope you can understand




    jo = UserForm1.IDsearch.Value

    For i = 3 To 10
    For Mee = 25 To 32
    Set y5 = (ActiveSheet.Cells(5, i))
    Set y6 = (ActiveSheet.Cells(jo, Mee))
    With ListBox2
    .AddItem y5.Value
    .List(u, 1) = y6
    u = u + 1
    End With
    Next Mee
    Next i
    End Sub

+ 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