简体   繁体   中英

Formula or macro to group cells according to their values

I am on a spreadsheet that needs to retitle cells based on the cell value and the values of the cells below it. Basically I have the below column, which is filled by a formula that links to another spreadsheet.

Column A
EE
EE
SP
EE
CH
CH
EE
SP
CH
CH
EE
  • For an cell that has EE , and for which the cell below it is EE , then the first cell should read "EE Only".
  • For any cell that has EE , and for which the cell below it is SP , which is then followed by another EE , then the first two cells should read "EE+SP".
  • For any cell EE where the cell(s) below it are CH , then those cells should read "EE+CH".
  • And for any cell EE where the cells below it are SP and CH , then all of those cells should read "EE+FAM".

The above column should then look like:

Column A
EE Only
EE+SP
EE+SP
EE+CH
EE+CH
EE+CH
EE+FAM
EE+FAM
EE+FAM
EE+FAM
EE Only

It's a long table of values, and quite honestly I'm not even sure what the best way to go about this is.

Do I need to create a table of values to lookup against, or is there a macro that would be able to handle this?

From your input example:

=IF(AND(A2<>"EE",B1="EE+FAM"),"EE+FAM",IF(AND(A2="EE",OR(A3="EE",A3="")),"EE Only",IF(OR(AND(A1="EE",A2="SP",A3="EE"),AND(A2="EE",A3="SP",A4="EE")),"EE+SP",IF(OR(A2="CH",A3="CH"),"EE+CH",IF(AND(A2="EE",A3<>"EE"),"EE+FAM","")))))  

should derive your output example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM