dan_sherbs
New Member
- Joined
- May 14, 2014
- Messages
- 25
Hi,
I'm trying to create a searchable knowledge database in Excel & having a bit of trouble editing some code i found to fit my requirements.
Basically I have a number of different worksheets representing different locations. They all have the same look and feel to them with rows of questions in column B and the corresponding answer in Column C.
I then have another worksheet called "Search". I want the user to enter a word/String in Cell B2, select the location from a drop down box in Cell B3, click a search button which runs a macro/some VBA code that displays all the results from Row 7 down with the question in column A and the answer is in Column B. Note I would like it so the word entered by the user is searched in both the question and answer columns and results displayed accodingly. (for example if the word "London" is in a question and also in another answer then the results will display both.
I have seen the following code which nearly gets what i want, is anybody able to provide some help how i modify this to make my requirement?
Many Thanks, code below..
Dan
I'm trying to create a searchable knowledge database in Excel & having a bit of trouble editing some code i found to fit my requirements.
Basically I have a number of different worksheets representing different locations. They all have the same look and feel to them with rows of questions in column B and the corresponding answer in Column C.
I then have another worksheet called "Search". I want the user to enter a word/String in Cell B2, select the location from a drop down box in Cell B3, click a search button which runs a macro/some VBA code that displays all the results from Row 7 down with the question in column A and the answer is in Column B. Note I would like it so the word entered by the user is searched in both the question and answer columns and results displayed accodingly. (for example if the word "London" is in a question and also in another answer then the results will display both.
I have seen the following code which nearly gets what i want, is anybody able to provide some help how i modify this to make my requirement?
Many Thanks, code below..
Dan
Code:
Sub SearchParts()
Dim arrParts() As Variant
Range("A7", "B" & Cells(Rows.CountLarge, "B").End(xlDown).Row).Clear
arrParts = FindParts(CStr(Trim(Cells(2, 2))))
Range("A7").Resize(UBound(arrParts, 2), UBound(arrParts)) = _
WorksheetFunction.Transpose(arrParts)
End Sub
Private Function FindParts(PartNumber As String) As Variant
Dim ws As Worksheet
Dim FoundCell As Range
Dim LastCell As Range
Dim rngParts As Range
Dim FirstAddr As String
Dim arrPart() As Variant
Set ws = Worksheets("Data")
Set rngParts = ws.Range("A2:B" & ws.Cells(Rows.CountLarge, "B").End(xlUp).Row)
With rngParts
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = rngParts.Find(What:=PartNumber, After:=LastCell, LookAt:=xlPart)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If
ReDim arrPart(1 To 2, 1 To 1)
Do Until FoundCell Is Nothing
arrPart(1, UBound(arrPart, 2)) = FoundCell.Offset(0, -1)
arrPart(2, UBound(arrPart, 2)) = FoundCell.Value
ReDim Preserve arrPart(1 To 2, 1 To UBound(arrPart, 2) + 1)
Set FoundCell = rngParts.FindNext(After:=FoundCell)
If FoundCell.Address = FirstAddr Then
Exit Do
End If
Loop
FindParts = arrPart
End Function