IF(Column X == value or value or value or value) write Column Y to F2 seperated by comma

MrPowerQuery

New Member
Joined
Aug 7, 2018
Messages
11
Hi there,

i looking for a formula or Language M code snippet or macro that does the following thing.

If in column "Sort" the number is either 66 or 46 or 23 or 19 or 18 or 6 write the value of column "Count" to field "F2" but seperated by a comma.

I tried some formula but didnt get the results i need.

Does someone have a idea?

greetz
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This is an example of the table. The real list has about 7.000 Rows

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Customer[/TD]
[TD]Nr[/TD]
[TD]Inprint[/TD]
[/TR]
[TR]
[TD]Customer A[/TD]
[TD]66[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Customer B[/TD]
[TD]23[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Customer C[/TD]
[TD]50[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Customer D[/TD]
[TD]6[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Customer E[/TD]
[TD]6[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]Customer F[/TD]
[TD]27[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]Customer G[/TD]
[TD]9[/TD]
[TD]7[/TD]
[/TR]
</tbody>[/TABLE]














Result should be like: "1, 4, 5"
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG16Aug05
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, nstr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .Add 66, ""
    .Add 46, ""
    .Add 23, ""
    .Add 19, ""
    .Add 18, ""
    .Add 6, ""
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        nstr = nstr & IIf(nstr = "", Dn.Offset(, 1).Value, ", " & Dn.Offset(, 1).Value)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
Range("F2").Value = nstr
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi MickG,

this worked perfect.
Thanks a lot!!!!

Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG16Aug05
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, nstr [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range("B2", Range("B" & Rows.Count).End(xlUp))
[COLOR=Navy]With[/COLOR] CreateObject("scripting.dictionary")
    .Add 66, ""
    .Add 46, ""
    .Add 23, ""
    .Add 19, ""
    .Add 18, ""
    .Add 6, ""
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    [COLOR=Navy]If[/COLOR] .Exists(Dn.Value) [COLOR=Navy]Then[/COLOR]
        nstr = nstr & IIf(nstr = "", Dn.Offset(, 1).Value, ", " & Dn.Offset(, 1).Value)
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]Next[/COLOR]
Range("F2").Value = nstr
[COLOR=Navy]End[/COLOR] [COLOR=Navy]With[/COLOR]
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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