Concaténer des cellules avec une condition

MadameHugo

New Member
Joined
Feb 25, 2020
Messages
9
Office Version
  1. 2010
Platform
  1. Windows
Good morning all,

I wanted to concatenate colors (in range B) with respect to each value which is in row A. (see image) . The result is in Range C.

I used concatenation with condition like this: = IF (A2 <> 0; CONCATENATE (B2; ","; B3; ","; B4; ","; B5; ","; B6); "" ) because sometimes there are empty cells in row A.

The problem is that sometimes there is 1 color, sometimes 2 colors, sometimes more! And my formula only works if there are 5 colors. Each time I have to change my formula manually ...

Someone can help me ? Thank you.
 

Attachments

  • contact_couleur_pb.png
    contact_couleur_pb.png
    29.3 KB · Views: 11

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
sometimes there are empty cells in row A.
  1. Note that "A" is a column, not a row. Incorrect terminology will confuse your helpers and possibly lead to a delayed or incorrect solution.

  2. If posting in the standard "Excel Questions" forum, please post in English, including your thread title. Note the sub-heading to the forum
    All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only

  3. For the future, I suggest that you investigate XL2BB for providing sample data to make it easier for helpers by not having to manually type out sample data to test with.

With Excel 2010, a worksheet formula solution could look like this. the helper column (D) could be hidden once the formulas are entered.

MadameHugo 2020-03-15 1.xlsm
ABCD
2xaa,ba
3b a,b
4xcc,d,ec
5d c,d
6e c,d,e
7xff,gf
8g f,g
9xhh,i,jh
10i h,i
11j h,i,j
12xkk,lk
13l k,l
14xmm,n,om
15n m,n
16o m,n,o
17xppp
18xqq,r,sq
19r q,r
20s q,r,s
21
Sheet1
Cell Formulas
RangeFormula
C2:C20C2=IF(A2="","",INDEX(D2:D$30,MATCH(TRUE,INDEX(LEN(D2:D$29)>=LEN(D3:D$30),0),0)))
D2:D20D2=IF(A2="",D1&","&B2,B2)
 
Upvote 0
A simplified version of Peter's suggestion without arrays.
Sample Data.xlsm
ABCD
1RefproductResultHelper
2aaa,ba,b
3b b
4acc,d,e,fc,d,e,f
5d d,e,f
6e e,f
7f f
8aggg
9ahh,i,jh,i,j
10i i,j
11j j
12akk,l,mk,l,m
13l l,m
14m m
15ann,o,p,q,rn,o,p,q,r
16o o,p,q,r
17p p,q,r
18q q,r
19r r
20ass,t,u,v,ws,t,u,v,w
21t t,u,v,w
22u u,v,w
23v v,w
24w w
Sheet17
Cell Formulas
RangeFormula
C2:C24C2=IF(A2="","",D2)
D2:D24D2=IF(A3<>"",B2,IF(D3<>"",B2&","&D3,B2))

You could also do it without the extra column by only using the formula in column D, then masking the rows where column A is blank with conditional formatting.
 
Upvote 0
Hello MadameHugo,

whats the maximum number of colors?

in Excel 365, there is a formula to do it, but i think you are using Excel 2010, so there isnt an easy formula to do it,

for maximum of 5 colors, you can use this formula (starting C2 for an example), its not pretty and completely dynamic but it doesnt need helper columns

=IF(A2<>"",B2&IF(A3="",","&B3&IF(A4="",","&B4&IF(A5="",","&B5&IF(A6="",","&B6,""),""),""),""),"")

if you need more colors you can expand the internal loop, if not this one is enough

Q
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,151
Members
449,068
Latest member
shiz11713

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