How can I select the next item and next item and next item?

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
686
Office Version
  1. 365
Platform
  1. Windows
Private Sub CommandButton1_Click()
For I = 0 To Me.ListBox4.ListCount - 1
If InStr(UCase(ListBox4.List(I, 1)), UCase(sFind)) > 0 Then
Me.ListBox4.TopIndex = I + 1
Me.ListBox4.ListIndex = I + 1
Exit For
End If
Next I
End Sub

How can I replace the "I + 1" with a variable to add 1 after every click?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What exactly is your code supposed to be doing?
 
Last edited:
Upvote 0
Try
Code:
Private Sub CommandButton1_Click()
Static k As Long
sFind = Me.TextBox4.Value
For i = k + 1 To Me.Listbox4.ListCount - 1
If InStr(UCase(Listbox4.List(i, 1)), UCase(sFind)) > 0 Then
   Me.Listbox4.TopIndex = i
   Me.Listbox4.ListIndex = i
   k = i
   Exit For
End If
If i = Me.Listbox4.ListCount - 1 Then k = 0
Next i
End Sub
 
Upvote 0
Rick,

After It searches what I typed in a textbox, I want this command button to find the next line that matches, and then the next line and next line.
 
Upvote 0
Fluff,

Thanks again! This selects the next items on the list. I just need to add a better filter.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top