VBA code to find matching values

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,584
Office Version
  1. 365
Platform
  1. Windows
NamesGuess
John5
Tom5
Addy6
Abby5
Daddy8
Final Result5


There are three people's values that are matching the final Result. Msgbox required to show the names of the person whose value matches the final result.

Output: Msgbox is required as shown below:

1587553706698.png

The above Msgbox has been created manually for demo purpose.

Any help is highly appreciated.
 
Bit late, just for the fun of it, here's my solution.
VBA Code:
Sub snjpverma()
   Dim x As Variant
   x = Join(Filter([transpose(if(b2:b6=b9,a2:a6,false))], False, False), ",")
   MsgBox StrReverse(Replace(StrReverse(x), ",", " & ", 1, 1))
End Sub
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Bit late, just for the fun of it, here's my solution.
VBA Code:
Sub snjpverma()
   Dim x As Variant
   x = Join(Filter([transpose(if(b2:b6=b9,a2:a6,false))], False, False), ",")
   MsgBox StrReverse(Replace(StrReverse(x), ",", " & ", 1, 1))
End Sub
Wow, this seems pure magic. So elegant!

I'll study this later when time permits. Thanks so much Fluff.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Bit late, just for the fun of it, here's my solution.
VBA Code:
Sub snjpverma()
   Dim x As Variant
   x = Join(Filter([transpose(if(b2:b6=b9,a2:a6,false))], False, False), ",")
   MsgBox StrReverse(Replace(StrReverse(x), ",", " & ", 1, 1))
End Sub

Hi fluff,
I just tried to incorporate this in a different workbook by giving it the worksheet name "Calc" and it says type mismatch on the line highlighted in Red.
Also, instead of msgbox I gave the final output to the variable x again, as highlighted in Green below. I hope that won't cause any problem to the code further. Right now, i am unable to check that due to type mismatch on the Red line.
I have planned to put this text in a cell rather than in a msgbox.

Rich (BB code):
Dim x as variant
x = Join(Filter([transpose(if(calc.range("b2:b6")=calc.range("b9"),calc.Range("a2:a6"),false))], False, False), ",")
x = StrReverse(Replace(StrReverse(x), ",", " & ", 1, 1))
calc.range("c15") = x
 
Upvote 0
You need to do it like
VBA Code:
   x = Join(Filter([transpose(if(raw!b2:b6=raw!b9,raw!a2:a6,false))], False, False), ",")
where "raw" is the actual sheet name
 
Upvote 0
If you want to do it like you tried, it would need to be
VBA Code:
   x = Join(Filter(calc.Evaluate("transpose(if(" & Range("B2:B6").Address & "=" & Range("B9").Address & "," & Range("A2:A6").Address & ",false))"), False, False), ",")
 
Upvote 0
If you want to do it like you tried, it would need to be
VBA Code:
   x = Join(Filter(calc.Evaluate("transpose(if(" & Range("B2:B6").Address & "=" & Range("B9").Address & "," & Range("A2:A6").Address & ",false))"), False, False), ",")
Thanks Fluff. It's sorted.
It wouldn't be possible without your support.
I realized that when the values in B2:B6 were errors it was giving a type mismatch error.
The moment I used Iferror and replaced the errors with "" , your code worked.

Thanks again.
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,424
Members
449,450
Latest member
gunars

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