Consulting

Results 1 to 3 of 3

Thread: Listbox Selection not working with 1 result

  1. #1

    Listbox Selection not working with 1 result

    Hello,

    what are we doing wrong ?
    it seems it works fine if we have like 2 or more results
    it will be selected the last row

    but when we have 1 result it don't select anything

    'select last row
    With ListBox1
        For i = .ListCount - 1 To 0 Step -1
           If .List(i, 0) <> "" Then
              .ListIndex = .ListCount - 1 
    'or even this code also work with last row
              .ListIndex = i 
               Exit For
           End If
        Next i
     End With
    any idea's?

    -Thanks

    -updated
    not working
    .SetFocus
    .ListIndex(0) = True
    'Solved
    seems we got our code to more selection instead of 1

    If (n - 1) < 2 Then ' this was the problem i had added the code not here but instead under it 
    ElseIf (n - 1) > 1 Then 'code was here seems the wrong place :banghead:
    Last edited by SamT; 01-19-2020 at 06:57 PM. Reason: indents

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Maybe I did not understand the problem, but maybe such a code is enough:
      With Me.ListBox1    .ListIndex = .ListCount - 1
      End With
    Artik

  3. #3
    Thanks Artik
    this option also work

Posting Permissions

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