PDA

View Full Version : excel as a search engine



smruti
05-25-2017, 12:27 AM
I have 3 sheets of data. 1st sheet has data like this:




CDC 21
7.7 (20592)
8.8. (20941)
9.8. (20941)


CDC 50
7.3 (20941)
8.2(20591)
9.2(20591)



























2nd sheet has the search button(macro) and the input cell
3rd sheet has data like this


7.7 (20592)
1-E-1


7.1(20592)
1-E-1





8.8. (20941)
1-I-1.....




When I enter CDC 21/23 in my input cell in sheet 2, I want excel to search for 7.7 (20592),8.8. (20941)( i.e row corresponding to my input in sheet1) in the 3rd sheet and return me the adjacent column values from the 3rd sheet( here, 1-E-1, 1-I-1 and so on)
Following is the code i wrote

Sub sku()

Dim erow As Long
Dim ws As Worksheet
Dim lastrow As Long
Dim count As Integer
Dim x As Integer
Dim y As Integer
Dim z As Integer
lastrow = Sheets(1).Cells(Rows.count, 1).End(xlUp).Row
lastrow1 = Sheets(3).Cells(Rows.count, 1).End(xlUp).Row
lastcolumn = Sheets(1).Cells(1, Columns.count).End(xlUp).Column

For x = 2 To lastrow
If Sheets(1).Cells(x, 1) = Sheets(2).Range("A2") Then
For y = 3 To lastcolumn
For z = 1 To lastrow1
If Sheets(1).Cells(x, y) = Sheets(3).Cells(z, 1) Then
Sheets(2).Range("J& z") = Sheets(3).Cells(z, 2)
End If
Next z
Next y
End If
Next x

End Sub

The code shows no error but does not work. On debugging it shoed that the cursor does not enter the inner for loops at all.
Can u plz help?

GTO
05-25-2017, 12:52 AM
Cross-posted here (https://www.mrexcel.com/forum/excel-questions/1006749-excel-search-engine.html)

smruti,

Please read A message to forum cross posters (http://www.excelguru.ca/content.php?184)

Hope that helps,

Mark