Google Sheets公式问题:如何将指定字符串仅填充至特定行
Google Sheets 公式修正:仅匹配指定城市时填充区域
问题场景
你使用公式 =IF(COUNTIF(P3:P300,"Liverpool"),"North West","") 试图实现:当Town列(P列)某行内容为"Liverpool"时,在Region列(V列)对应行填入"North West",否则留空。但当前公式会将"North West"填充至所有行,仅期望第3、5行显示该内容。
当前错误效果:
| Name | Town | Region |
|---|---|---|
| School 1 | Salisbury | North West |
| School 2 | Leeds | North West |
| School 3 | Liverpool | North West |
| School 4 | Birmingham | North West |
| School 5 | Liverpool | North West |
错误原因
COUNTIF(P3:P300,"Liverpool") 的作用是统计P3到P300范围内包含"Liverpool"的单元格总数,只要该范围内存在至少一个匹配项,就会返回大于0的数值。而IF函数会将所有非0数值判定为TRUE,因此所有行都会返回"North West"。
修正方案
需要针对单行单元格进行判断,而不是统计整个区域。使用以下公式:
=IF(P3="Liverpool","North West","")
将该公式输入到V3单元格,然后下拉填充至V300即可。
修正后效果
| Name | Town | Region |
|---|---|---|
| School 1 | Salisbury | |
| School 2 | Leeds | |
| School 3 | Liverpool | North West |
| School 4 | Birmingham | |
| School 5 | Liverpool | North West |
内容的提问来源于stack exchange,提问作者ShaqSD
相关产品推荐
相关产品推荐

