# Matching rows of data with another

#### everscern

##### Board Regular
Hi all,
this is the crux of my project. but i really am at wits end. pls help. I would very much appreciate.

i have 3 rows. one row is the variable.

column 1 = 1 2 3
column 2 = 1 2 3
column 3 = 4 5 6
with parameters 1,2 3 , column 2 will have a stock of 10.
with parameter 4,5,6 , column 3 will have a stock of 20.

now, comparing column 1, 2,3. column 1 and 2 is similar. Thus, column 1 must return a stock value of 10 too.

I need a macro for this. Thanks in advance.. :wink: [/list]

### Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

#### jindon

##### MrExcel MVP
How do you know 1 2 3 has 10 and 4 5 6 has 20?

When you say similar, 1 2 3 and 1 2 4 are similar?

#### everscern

##### Board Regular
sorry for my unclear explaination.
1=material A 2=material B 3=material C 4=material D 5=material E 6=material F

so in column two, we have 1,2,3. That means the toy is made of material A,B,C. and in the stock, we have ten of such toys. That's how i got the number 10.

in column 3, i have 4,5,6. meaning another toy is made of material D,E,F.
in the stock, there are twenty such toys.

So in column one, a buyer specifies the exact parameters of the first toy. the return should be 10 right?

so i need to get this in a macro? thanks

#### jindon

##### MrExcel MVP
so in column two, we have 1,2,3. That means the toy is made of material A,B,C. and in the stock, we have ten of such toys. That's how i got the number 10.

I understand the part before above.

It doesn't say anything about how 1,2,3 is connected to 10.

and is it 1 2 3 or 1,2,3 or 1, 2, 3 ?

You need to be very careful for this kind of question.

#### everscern

##### Board Regular

it will look something like this.

i want the question mark to be 10.

I meant there are 10 toys made up of material A,B,C

#### jindon

##### MrExcel MVP
Assuming you are entering A1:A3 and list start from C1...
Paste the code onto sheet module
Code:
``````Private Sub Worksheet_Change(ByVal Target As Range)
Dim txt As String, r As Range
With Target
If Intersect(.Cells,Range("a1:a3")) Is Nothing Then Exit Sub
If WorksheetFunction.CountA(Range("a1:a3"))<>3 Then Exit Sub
Application.EnableEvents = False
Range("a4") = Empty
txt = Range("a1").Text & "_" & Range("a2").Text & "_" & Range("a3").Text
For Each r In Range("c1",Cells(1,Columns.Count).End(xlToLeft))
If txt = r.Text & "_" & r.offset(1).Text & "_" & r.Offset(2).Text Then
Range("a4").Value = r.Offset(3).Value
Exit For
End If
Next
End With
Application.EnableEvents = True
End Sub``````

#### everscern

##### Board Regular

sorry to disturb u once more. But i did what you told me but i've got this dialog box. how do i link the macro to a button. my button is 'button2'

#### jindon

##### MrExcel MVP
Previous code runs automatically when you filled A1:A3

If you want to attach the code to CommandButton2_Click event then
change to
Code:
``````Private Sub CommandButton2_Click()
Dim txt As String, r As Range

If WorksheetFunction.CountA(Range("a1:a3"))<>3 Then Exit Sub
Range("a4") = Empty
txt = Range("a1").Text & "_" & Range("a2").Text & "_" & Range("a3").Text
For Each r In Range("c1",Cells(1,Columns.Count).End(xlToLeft))
If txt = r.Text & "_" & r.offset(1).Text & "_" & r.Offset(2).Text Then
Range("a4").Value = r.Offset(3).Value
Exit For
End If
Next
End With
End Sub``````

#### everscern

##### Board Regular
thanks so much. it really worked!!

#### everscern

##### Board Regular
Hi..I tried to tweak the code to suit my situation. But somehow everything turned out worse.

I used to following code:

Private Sub Button24_Click()
Dim txt As String, r As Range

If WorksheetFunction.CountA(Range("b3:b9")) <> 7 Then Exit Sub
Range("b11") = Empty
txt = Range("b3").Text & "_" & Range("b4").Text & "_" & Range("b5").Text& "_"& Range("b6").Text& "_"& Range("b7").Text& "_"& Range("b8").Text& "_"& Range("b9").Text
For Each r In Range("s3", Cells(1, Columns.Count).End(xlToLeft))
If txt = r.Text & "_" & r.Offset(1).Text & "_" & r.Offset(2).Text Then
Range("b11").Value = r.Offset(3).Value
Exit For
End If
Next
End With
End Sub

for

Replies
6
Views
462
Replies
2
Views
137
Replies
0
Views
94
Replies
2
Views
93
Replies
2
Views
158

1,141,023
Messages
5,703,797
Members
421,318
Latest member
cg_cartoonexcel

### 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.

### Which adblocker are you using?

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

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