简体   繁体   English

如果范围内只有一个单元格有值,如何将单元格范围内的值复制到另一个单元格?

[英]How to copy the value in a range of cells to another cell if only one cell in the range has a value?

I have 40 columns and several hundred rows in an Excel spreadsheet. 我在Excel电子表格中有40列和几百行。

Range C6:AQ6, C7:AQ7, C8:AQ8, and so on

CASE 1: Only one cell in the range D6:AQ6 usually contains a value. 
CASE 2: In some rare cases, more than one cell OR no cells contain a value in this range.

Here is what I want to accomplish: 这是我要完成的工作:

If CASE 1: Populate the cell C6 with the value in the only cell in the range D6:AQ6.
If CASE 2: Leave C6 blank

How do I do this using Excel formulae? 如何使用Excel公式执行此操作?

Enter this formula into Cell C6: 在单元格C6中输入以下公式:

=IF(COUNTA(D6:AQ6)=1,INDEX(D6:AQ6,Match("*",D6:AQ6,0)),"")

How it works: 这个怎么运作:

  • Count's how many Cells in the range "D6:AQ6" are not blank. 计算“ D6:AQ6”范围内的单元格数量是否为空白。
    • If there is only 1 cell with data (Case1) 如果只有1个包含数据的单元格(情况1)
      • Then use index to return the value 然后使用索引返回值
        • Index works by returning the value form the cell X to the right where X is the first column Match finds that has anything inside of it 索引通过从右侧的单元格X返回值来工作,其中X是Match发现其中包含任何内容的第一列
    • If there is not 1 (more than 1 or 0, Case2) 如果不存在1(大于1或0,则为Case2)
      • then set the cell to blank 然后将单元格设置为空白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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