Hello! Fairly new to VBA and appreciative of any help! Basically, I am trying to search down a column on a spreadsheet and add the rows that correspond to the search criteria into a listbox.
Objective:
1. User enters number on UserForm in text box
2. User hits "Generate Report" button and the macros searches down column C of the active spreadsheet (there is only one worksheet)
3. Once a match is found, the entire row is selected from columns A to X and the row added to a listbox on the UserForm
Problems:
1. I have been able to code and display the what I searched for in the first column, but not the entire row using the code. This finds the correct number of entries, but displays them in the first column of the listbox only where I want the entire row displayed.
Private Sub cmdGenerateReport_Click()
Dim x As String
strSearch = LotNumberTxt.Text
A = 3
Do
x = Cells(A, 3).Value
If x = "" Then Exit Sub
If x = strSearch Then Me.ListBoxReport.AddItem x
A = A + 1
Loop Until Cells(A, 3).Value = ""
End Sub
2. When I activate the row from columns A to X the "Object Required" Error comes up even though I defined y (new variable) as a range.
Private Sub cmdGenerateReport_Click()
Dim x As String
Dim y As Range
strSearch = LotNumberTxt.Text
A = 3
Do
x = Cells(A, 3).Value
If x = "" Then Exit Sub
If x = strSearch Then Cells(A, 3).Select
Set y = Range("A" & ActiveCell.Row & ":X" & ActiveCell.Row).Select
A = A + 1
Loop Until Cells(A, 3).Value = ""
End Sub
So, if anybody can help me select the range and add it to the listbox (I thought AddItem would work but it does not seem to) that would be great! Any suggestions are appreciated. Thanks!
Bookmarks