简体   繁体   中英

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.

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?

Enter this formula into Cell 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.
    • If there is only 1 cell with data (Case1)
      • 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
    • If there is not 1 (more than 1 or 0, Case2)
      • then set the cell to blank

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