excel as a search engine

smruti

New Member
Joined
May 24, 2017
Messages
3
Hello,
I'm trying to develop a vba code to use excel as a search engine. I have created a cell which bears the input(in sheet(2)). I want excel to search for the input(which lies in the first column of Sheet(1)) , once it's found, take every column corresponding to the result and search for it in sheet(3). If found there, it should return me the value in its adjacent cell(sheet(3)) at a defined place in sheet(2)
Here's my code for it. Can anyone please help me with it?
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #fffb00}span.s1 {color: #000000}span.s2 {color: #011993}</style>
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
lastcolum = 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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You need to state what your issue actually is other than the line below is wrong.
Code:
Sheets(2).Range("J& z") = Sheets(3).Cells(z, 2)
possibly should be...
Code:
Sheets(2).Range("J" & z) = Sheets(3).Cells(z, 2)
 
Upvote 0
Hi MARK858
I have 3 sheets of data. 1st sheet has data like this:
[TABLE="width: 4064"]
<colgroup><col span="32"></colgroup><tbody>[TR]
[TD]CDC 21/23[/TD]
[TD]7.7 (20592)[/TD]
[TD]8.8. (20941)[/TD]
[TD]9.8. (20941)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 4064"]
<colgroup><col span="32"></colgroup><tbody>[TR]
[TD]CDC 50...[/TD]
[TD]7.2 20591[/TD]
[TD]8.6 (20956) [/TD]
[TD] 9.7 (20941)[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
2nd sheet has the search button(macro) and the input cell
3rd sheet has data like this
[TABLE="width: 243"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]7.7 (20592)[/TD]
[TD]1-E-1[/TD]
[/TR]
[TR]
[TD]7.1(20592)[/TD]
[TD]1-E-1[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 243"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]8.8. (20941)[/TD]
[TD]1-I-1.....[/TD]
[/TR]
</tbody>[/TABLE]

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)

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?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top