Matching 2 cells value on product code

Excelnewbie001

Board Regular
Joined
Jan 25, 2017
Messages
79
Looking for some solution code in Vba to match and display if there is an exact match of 2 cells with column VW values -values in red..if there is a match the product code must be written in column Y....sorry I did not write an additional column for Y. Inexample Product Code 50 and 55 have matches....so there Y columns would have had 50 and 55.Only 1 row must be checked on product code the row have the products codes values.Each row must be checked for a match on the product codes value. I am sure this can be done with a formula or vba function ? I have over 200 product codes and this will help me tremendously. Help will be greatly appreciated to achieve above Thank you
A
ABCDEFV
W
X Product Code
38
40
102025303538
4050
410153030354048
50
51
6
152040354050585552
8
203050404555686053
10253560455060787054
123088
75
506070887555
14
355080557075988056
164055906075801088557
184575100658085118
9058

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Heres a formula for Y1 and then drag down:

=IF(SUMPRODUCT(COUNTIFS(A1:G1,V1:W1))=2,X1,"")

If you need VBA you will need to provide the sheet name.
 
Upvote 0
Or maybe this as it caters for the number appearing more than once:

=IF(AND(COUNTIF(A1:G1,V1),COUNTIF(A1:G1,W1)),X1,"")
 
Upvote 0
You are correct there will be possible more than 1 exact matches in the row.....This will be a timesaver of note thank you very much
 
Upvote 0
There will be a multitude of ways to do this in VBA. Heres one:

Code:
Dim arr()
With Sheets("Sheet1")
    lr = .Range("A" & Rows.Count).End(xlUp).Row
    ReDim arr(1 To lr)
    For i = 1 To lr
        If Not IsError(Application.Match(.Cells(i, 22), Range(.Cells(i, 1), .Cells(i, 7)), 0)) Then
            If Not IsError(Application.Match(.Cells(i, 23), Range(.Cells(i, 1), .Cells(i, 7)), 0)) Then
                arr(i) = .Cells(i, 24).Value
            End If
        End If
    Next
    Range(.Cells(1, 25), .Cells(lr, 25)) = Application.Transpose(arr)
End With
 
Upvote 0
Steve this works but it will also see 100 85 as 85 100 as a match on 100 85......Just tested it unless I am doing something wrong here

=IF(AND(COUNTIF(A1:G1,V1),COUNTIF(A1:G1,W1)),X1,"")
 
Upvote 0
There will be a multitude of ways to do this in VBA. Heres one:

Code:
Dim arr()
With Sheets("Sheet1")
    lr = .Range("A" & Rows.Count).End(xlUp).Row
    ReDim arr(1 To lr)
    For i = 1 To lr
        If Not IsError(Application.Match(.Cells(i, 22), Range(.Cells(i, 1), .Cells(i, 7)), 0)) Then
            If Not IsError(Application.Match(.Cells(i, 23), Range(.Cells(i, 1), .Cells(i, 7)), 0)) Then
                arr(i) = .Cells(i, 24).Value
            End If
        End If
    Next
    Range(.Cells(1, 25), .Cells(lr, 25)) = Application.Transpose(arr)
End With


Thank you so much.....let me test quickly.....I would like to add button now that I think so a macro will be an BONUS.Let me test quickly and report back to you thank you so very much for your help.
 
Upvote 0
This version will only match should the searched for values be in adjacent cells in the correct order:

Code:
Dim arr()
With Sheets("Sheet1")
    lr = .Range("A" & Rows.Count).End(xlUp).Row
    ReDim arr(1 To lr)
    For i = 1 To lr
        myMatch = Application.Match(.Cells(i, 22), Range(.Cells(i, 1), .Cells(i, 7)), 0)
        If Not IsError(myMatch) Then
            If .Cells(i, myMatch + 1) = .Cells(i, 23) Then
                arr(i) = .Cells(i, 24).Value
            End If
        End If
    Next
    Range(.Cells(1, 25), .Cells(lr, 25)) = Application.Transpose(arr)
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,217,061
Messages
6,134,352
Members
449,869
Latest member
andrewtbi

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