VB Code:
Private Sub Search_Click()
Dim sht As Worksheet
Dim lngMaxRows As Long, lngRow As Long 'lngMaxRows = total rows
Dim lngItem As Long
'On Error Resume Next 'this is VERY bad while writing code (it may be hiding the problem)
Sheets("Month").Activate
Set sht = ActiveSheet
DisplayResults.Clear ' Clears the display results listbox in userform
lngMaxRows = Cells(65535, 13).End(xlUp).Row ' Works out what the last row is
For lngRow = 1 To lngMaxRows ' Checks from row 1 to lngMaxRow defined above
If QuerySearch.SearchAmount.Value = sht.Cells(lngRow, 13).Value Then
DisplayResults.AddItem ""
lngItem = QuerySearch.DisplayResults.ListCount
' Adds columns on the worksheet to cells in the listbox
QuerySearch.DisplayResults.Column(0, lngItem) = sht.Cells(lngRow, 13)
QuerySearch.DisplayResults.Column(1, lngItem) = sht.Cells(lngRow, 4)
QuerySearch.DisplayResults.Column(2, lngItem) = sht.Cells(lngRow, 7)
QuerySearch.DisplayResults.Column(3, lngItem) = sht.Cells(lngRow, 8)
End If
Next
Set sht = Nothing
End Sub
I would strongly recommend removing the line "On error resume next", as this will just hide any errors from you. While you are writing code, this is far worse than having no error handling at all.