Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Tutorial] Find Excel (Macro)
- http://pastebin.com/RfBZEW00
- Search a value in column © row...[Excel VBA]
- http://pastebin.com/di3tdZEJ
- Question:
- I have a Excel woorksheet with columns and rows that contains different types of data. I want to create a search macro using VBA in Excel, so when I write a criteria in a textbox and then click on a commandbutton, I want the macro to search throw a specified column and find that criteria and then write the data
- that contains that row in textboxes, for example if I have 6 colums and 10 rows that contains data and in the first colum I have numbers, so if I serach for number 5 I want all data in the row to show in 6 differents textboxes.
- Answer:
- Private Sub SearchButton_Click()
- SearchString = InputBox("Enter Search String", "Search")
- If SearchString = "" Then Exit Sub
- For Each c In Range(myRange)
- If InStr(LCase(CStr(c)), LCase(SearchString)) Then
- Texbox1 = Cells(c.Row, 1)
- Texbox2 = Cells(c.Row, 2)
- Texbox3 = Cells(c.Row, 3)
- Texbox4 = Cells(c.Row, 4)
- Texbox5 = Cells(c.Row, 5)
- End If
- Next c
- MsgBox "Reached End of Report", , "Search Ended"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement