Excel VBA: Searching for value in listbox based on value set in textbox

Mario

I am trying to write a code for a search button which searches a listbox based a specific input set in a textbox. The values searched are always numbers, and the listbox contains values from a single column. The code i wrote can be found below but i don't understand why it is not functional.

Legend:

  • SearchButton: A Button which upon clicking is supposed to initiate the search
  • SearchBox: The textbox which will contain the search value
  • AvailableNumberList: The listbox which contains the data

Thanks for your help :)

Private Sub SearchButton_Click()
Dim SearchCriteria, i, n As Double
SearchCriteria = Me.SearchBox.Value
n = AvailableNumberList.ListCount
For i = 0 To n - 1
If SearchCriteria = i Then
AvailableNumberList.ListIndex = i
End If
Next i
End Sub
Siddharth Rout

Is this what you are trying?

'If SearchCriteria = i Then
If AvailableNumberList.List(i) = SearchCriteria Then

Also use Exit For once a match is found :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to use the listbox value to update textbox

From Dev

Excel VBA to select a range based on cell value

From Dev

VBA increment the "#" in TextBox#.value

From Dev

Listbox DataTemplate clear textbox value on selection

From Dev

VBA - Set Range for function Based on Header Value

From Dev

VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

From Dev

VBA Access - TextBox Value to String

From Dev

Searching for a non-numeric value in VBA Excel

From Dev

Excel VBA: Color range based on cell value

From Dev

VBA Excel 2010 format textbox value as currecy

From Dev

VBA - Set Range for function Based on Header Value

From Dev

Excel VBA: Searching for value in listbox based on value set in textbox

From Dev

VBA Access - TextBox Value to String

From Dev

Create cells value based on formula in Excel VBA

From Dev

Excel VBA: Add Value to TextBox based on ComboBox Selection Then Sum

From Dev

Listbox Sorting based on TextBox value

From Dev

Excel VBA get complete textbox value

From Dev

Set TextBox Based on Value From DropdownList (populated by database) on initial Load

From Dev

How to set condition in excel vba based on cell value?

From Dev

check if a textbox value already exists in a listbox

From Dev

VBA Textbox to number value

From Dev

assigning value to dynamically built textbox name using excel vba

From Dev

Convert TextBox.Value to Double into VBA (Excel 2013)

From Dev

Set value of a cell based on another cell's value in VBA Excel 2010

From Dev

Select a value in Listbox and set focus over that value - VBA

From Dev

VBA Filter (Searching Interger Value)

From Dev

vba listbox value matches list

From Dev

VBA Userform Populate textbox with cell value based on 2 combobox selections

From Dev

VBA Update Textbox Value based on Option Button Selection

Related Related

  1. 1

    how to use the listbox value to update textbox

  2. 2

    Excel VBA to select a range based on cell value

  3. 3

    VBA increment the "#" in TextBox#.value

  4. 4

    Listbox DataTemplate clear textbox value on selection

  5. 5

    VBA - Set Range for function Based on Header Value

  6. 6

    VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

  7. 7

    VBA Access - TextBox Value to String

  8. 8

    Searching for a non-numeric value in VBA Excel

  9. 9

    Excel VBA: Color range based on cell value

  10. 10

    VBA Excel 2010 format textbox value as currecy

  11. 11

    VBA - Set Range for function Based on Header Value

  12. 12

    Excel VBA: Searching for value in listbox based on value set in textbox

  13. 13

    VBA Access - TextBox Value to String

  14. 14

    Create cells value based on formula in Excel VBA

  15. 15

    Excel VBA: Add Value to TextBox based on ComboBox Selection Then Sum

  16. 16

    Listbox Sorting based on TextBox value

  17. 17

    Excel VBA get complete textbox value

  18. 18

    Set TextBox Based on Value From DropdownList (populated by database) on initial Load

  19. 19

    How to set condition in excel vba based on cell value?

  20. 20

    check if a textbox value already exists in a listbox

  21. 21

    VBA Textbox to number value

  22. 22

    assigning value to dynamically built textbox name using excel vba

  23. 23

    Convert TextBox.Value to Double into VBA (Excel 2013)

  24. 24

    Set value of a cell based on another cell's value in VBA Excel 2010

  25. 25

    Select a value in Listbox and set focus over that value - VBA

  26. 26

    VBA Filter (Searching Interger Value)

  27. 27

    vba listbox value matches list

  28. 28

    VBA Userform Populate textbox with cell value based on 2 combobox selections

  29. 29

    VBA Update Textbox Value based on Option Button Selection

HotTag

Archive