如何在 Google 表格中特定列的输入上添加并突出显示行

问题描述 投票:0回答:2

在随附的谷歌表格中。

Google 表格 - https://docs.google.com/spreadsheets/d/1KxqaI-GYWur0Knt_bShI0GURucqU_cawu_sCoG_8Xlc/edit?usp=sharing

我需要对输入执行以下两个操作。

  1. 如果任何用户将 K 列中的值设置为 1,则添加与
    ID
    相同数量的行。

例如,如果我在 K 列中为

ID
=
ID_3
输入 1,它有 5 行,我想在
ID_3
的最后一个实例下方附加这五行,并且在附加行中所有值都应该是与
ID_3
相同,除了 C 列现在为
ID_3_Append
,K 列和 O 列对于附加行应为空白。

  1. 如果有人在 M 列中输入值 1,我们需要检查它属于哪个

    ID
    ,并在 E、F 和 G 列中查找该 id,如果
    ID
    针对哪个用户,则用红色突出显示行提供的输入为 1 可在 E、F 和 G 列中找到。

  2. 如果有人在更改类型中将值添加为 1,我需要将

    Test_1
    工作表中的 B 列从
    Put_list
    更新为 I,但希望保留
    Mark Status
    作为通用 ID(如果它有任何
    Mark Status) between earlier 
    ) Test_1
    and
    Put_list` 不变。此外,我们需要相应地突出显示依赖行。

将 B 列更新为 I 后,我们需要将名称从“Call”更改为“Put”。

google-sheets google-sheets-formula array-formulas google-sheets-query gs-vlookup
2个回答
4
投票

用途:

=ARRAYFORMULA(QUERY({QUERY({Test_1!A:O; 
 IFERROR(IF(IFNA(VLOOKUP(Test_1!C2:C, SORT({Test_1!C2:C, Test_1!K2:K}, 2, 0), 2, 0))=1, 
 {Test_1!A2:A, Test_1!B2:B, Test_1!C2:C&"_Append", Test_1!D2:J, Test_1!X2:X*0, 
  Test_1!L2:L, Test_1!X2:Y*0, Test_1!O2:O}, 
 {"","","","","","","","","","","","","","",""}), 
 {"","","","","","","","","","","","","","",""})}, 
 "where Col1 is not null and not Col3 matches '"&
 TEXTJOIN("|", 1, "×", UNIQUE(IF(IFNA(VLOOKUP(Test_1!C2:C, 
 SORT({Test_1!C2:C, Test_1!N2:N}, 2, 0), 2, 0))=1, Test_1!C2:C, )))&"' order by Col3", 1);
  
 IF(LEN(TEXTJOIN("|", 1, 
 UNIQUE(IF(IFNA(VLOOKUP(Test_1!C2:C, SORT({Test_1!C2:C, Test_1!N2:N}, 2, 0), 2, 0))=1, Test_1!C2:C, ))))>0, 
 QUERY({IF(Put_list!A2:A="",,IFERROR(Put_list!A2:A*1, "Put")), Put_list!A2:H, 
 IFNA(VLOOKUP(Put_list!B2:B&"♦"&COUNTIFS(Put_list!B2:B, Put_list!B2:B, ROW(Put_list!B2:B), "<="&ROW(Put_list!B2:B)), 
 {Test_1!C2:C&"♦"&COUNTIFS(Test_1!C2:C, Test_1!C2:C, ROW(Test_1!C2:C), "<="&ROW(Test_1!C2:C)), Test_1!J2:O}, {2,3,4,5,6,7}, 0))}, 
 "where Col3 matches '"&TEXTJOIN("|", 1, 
 UNIQUE(IF(IFNA(VLOOKUP(Test_1!C2:C, SORT({Test_1!C2:C, Test_1!N2:N}, 2, 0), 2, 0))=1, Test_1!C2:C, )), 
 UNIQUE(IF(IFNA(VLOOKUP(Test_1!C2:C, SORT({Test_1!C2:C, Test_1!N2:N}, 2, 0), 2, 0))=1, Test_1!C2:C&".+", )))&"'"), 
 {"","","","","","","","","","","","","","",""})}, "where Col1 is not null order by Col3", 1))

enter image description here


enter image description here

step-by-step transcript:

we start with array of {C, K} columns that we sort based on K column so if K column contains 1 then it will be moved up                                                 
this is convinient for VLOOKUP coz it will always look for 1st unique value eg. exactly wat we need if our array is sorted                                                  
so we vlookup C values to match our sorted array and return column K for all same IDs                   2 stands for 2nd column from sorted array and 0 stands for "exact match"                                
if no match is found vlookup will output #N/A error so we wrap it into IFNA - then if no match is found vlookup will output empty rows                                                  
then we put this into IF statement... if our vlookup outputs 1, we output our columns (again in {array} form                                                    
if our vlookup outputs 0 then we output array of 15 empty cells in a row {"","","", .....}                  this is because we use arrays {} and all ranges in arrays needs to be of same size                              
                    our table has 15 columns so if some error would happen the we would get error in one single cell aganist our 15 columns                                 
                    this way we avoid "array_literal error" having {15 columns; 15 cells in a row which is also 15 columns}                             
                    ; semicolon puts these two arrays/ranges under each other while , comma will put then next to each other                                
so if vlookup results in 1 then we assemble our array with ranges... A, B columns are same then we append to C column the phrase "_Append" with &                                                   
D:J columns are same... then we force column of zeros by multipling random empty column (X) with 0                      etc.                            
then again we use {"","","", ....} within IFERROR to deal with any possible error at this point                                                 
next we put all written above under our whole range Test_1!A:O and we wrap it into QUERY where we state to filter out all empty rows where Col1 is empty and 2nd condition of our query states                                                  
that Col3 of our array cant match our regex pattern which we assemble with TEXTJOIN formula                                                 
    | stands for "or" in regex. 1 in textjoin means "all non empty cells". then we use × (unique symbol) in case textjoin would output empty cell on its own resulting in some error somewhere                                              
    again we perform same vlookup, same ifna and same IF but now we output only C column and we are interested only into UNIQUE values                                              
then within the query we sort / order by Col3 our table and 1 at the end stands for "header rows"

                                                

3
投票

这可以回答您问题的第二部分。 选择要使用红色条件格式的行范围,例如示例表中的 A2:A12。 选择格式 - 条件格式,验证范围并应用自定义公式,如下所示:

=OR(
  IF($E2<>"NA",IFERROR(MATCH($E2,FILTER($C$1:$C$12,$M$1:$M$12=1),0)),0),
  IF($F2<>"NA",IFERROR(MATCH($F2,FILTER($C$1:$C$12,$M$1:$M$12=1),0)),0),
  IF($G2<>"NA",IFERROR(MATCH($G2,FILTER($C$1:$C$12,$M$1:$M$12=1),0)),0))

enter image description here

FILTER
提取更新列 ColM 中具有“1”的 ID。

MATCH
查看“依赖关系”列中的 ID 是否在该过滤列表中。

如果不匹配,

IFERROR
将结果设置为零。

初始的

IF
,过滤掉 Dependency 列中的 NA 值。

此逻辑会针对每个 Dependency 列进行复制,因此需要三个 IF。

整个内容都包含在 OR 函数中,因此如果任何依赖关系列具有匹配的 ID,则整行都会被标记为红色。

我已将其应用到添加到您的工作表 Test_1-GK 的选项卡中。

请告诉我这是否有帮助。

恐怕我不明白你问题的第一部分。我对这一点感到困惑:

我想在 ID_3 的最后一个实例下方附加五行,并且在附加行中,所有值都应与 ID_3 相同,除了 C 列(现在为 ID_3_Append)、K 列和 O 列(对于附加行来说应为空白)。

© www.soinside.com 2019 - 2024. All rights reserved.