Rstaub
06-26-2014, 12:57 AM
I am trying to write a very simple code. I want to search through a large database by Company Names. I my sheet labeled "search" I have a search box and I want to be able to use that value to search through the database and bring back the entire row for all companies matching that name. I know I have the correct code below but there seems to be a bug in it. I have been stumped for 3 days now and would really appreciate some help!!!
Sub finddata()
Dim Companyname As String
Dim finalrow As Integer
Dim i As Integer
Sheets("search").Range("a5:a100").ClearContents
Companyname = Sheets("Search").Range("a2").Value
finalrow = Sheets("Universe").Range("a3000").Row
For i = 2 To finalrow
If Sheets("universe").Cells(i, 10) = companyname Then
Range(Cells(i, 1), Cells(i, 41)).Select
Selection.Copy
Sheets("search").Select
ActiveSheet.Range("a100").end(xlup).Offset(1, 0).Paste
End If
Next i
End Sub
Sub finddata()
Dim Companyname As String
Dim finalrow As Integer
Dim i As Integer
Sheets("search").Range("a5:a100").ClearContents
Companyname = Sheets("Search").Range("a2").Value
finalrow = Sheets("Universe").Range("a3000").Row
For i = 2 To finalrow
If Sheets("universe").Cells(i, 10) = companyname Then
Range(Cells(i, 1), Cells(i, 41)).Select
Selection.Copy
Sheets("search").Select
ActiveSheet.Range("a100").end(xlup).Offset(1, 0).Paste
End If
Next i
End Sub