Consulting

Results 1 to 5 of 5

Thread: Loop inside if statement with listindex

  1. #1

    Post Loop inside if statement with listindex

    Hi, So this is all new to me. Started with VBA and learning as I go. Need some help on the following please. I am populating a combobox "Tech2" with a list of job numbers according to a name in the first combobox "Tech1". That all works fine. The problem starts when the job number has been used and are no longer available in "Tech2". I wrote an If function to change the listindex so that there are no blank spaces. I'm testing a few ideas but for some reason I get a invalid property value on this line of code "Me.Tech2.ListIndex = startnr"

    "[VBA]" Dim jobnr As String
    Dim startnr As Integer
    Dim endnr As Integer

    'Tech2 combobox populates according to the name in Tech1 combobox where the name is a named range
    jobnr = Tech1.Value
    Sheets("Lists").Activate 'named range scope are sheets("Lists")'
    Me.Tech2.RowSource = jobnr

    endnr = 10000

    If Me.Tech2 = "" Then
    For startnr = 1 To endnr
    Next startnr
    End If

    Me.Tech2.ListIndex = startnr "[/VBA]"

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is that loop before that line all about?

    Probably best to post your workbook and tell us how to reproduce ths situation.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Before I post the workbook let me try and explain. I have a named range. Lets call it "Steve". In that range there are a list of numbers. You can make it 1 -100. When I choose Steve in Combobox 1, Combobox 2 is being populated by the named range "Steve". That works. Now say I delete the 1 from the range. Combobox 2 still shows the empty cells. With listindex and the If function I can set the combobox that it shows the next value, but only if I type in all the values. I want to make it dynamic. I thought loop might do the trick.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It doesn't work that way for me. As you are setting te rowsource property, when you delete an entry, the 2nd combo updates and reflects this.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    I'll make a smaller sample workbook tonight and post it tomorrow.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •