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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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:
CDC 21/237.7 (20592)8.8. (20941)9.8. (20941)

<colgroup><col span="32"></colgroup><tbody>
</tbody>
CDC 50...7.2 205918.6 (20956) 9.7 (20941)

<colgroup><col span="32"></colgroup><tbody>
</tbody>
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

<colgroup><col><col></colgroup><tbody>
</tbody>
8.8. (20941)1-I-1.....

<colgroup><col><col></colgroup><tbody>
</tbody>

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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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