Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88029

search worksheet for user input value and return row information

$
0
0

I have a userform that has options for search criteria, once you select one of the option buttons, you insert a keyword for one of those options and then search multiple worksheets for this value. So if you select ID number for your criteria then insert a ID number as a keyword in a textbox, search all worksheets for the keyword and return the row information where the keyword is found in a message box.

Dim keyword As Variant
Dim i As Integer
Dim wb as ThisWorkbook
Dim ws as worksheet


keyword = ItemSearchForm.KeywordTextBox.Value


 If ItemSearchID.Value = True Then
        For each ws in wb
            For i = 0 to totalItems
              If .cells(i, 1).value = keyword then
                  MsgBox "ID: "& keyword &  vbCrLF & "Title: "& cells(i,2) & vbCrLF & "Author: "& cells(i, 3) & etc....

    End if

    Next i
    Next ws

    End if 

This does not work, how can I fix it. ALso if you select title instead of ID num for search criteria then it needs to be like this I assume.

 If ItemSearchID.Value = True Then
        For each ws in wb
            For i = 0 to totalItems
              If .cells(i, 1).value = keyword then
                  MsgBox "ID: "& cells(i,1) &  vbCrLF & "Title: "& keyword & vbCrLF & "Author: "& cells(i, 3) & etc....

    End if

    Next i
    Next ws

    End if 

Viewing all articles
Browse latest Browse all 88029

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>