简体   繁体   English

如果区域中只有一个单元格具有值,则将单元格区域中的值复制到另一个单元格

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

I have a range of cells M4:M18.我有一系列单元格 M4:M18。 In that range of cells is a formula referencing another table, there will only be one date in this range of cells.在该单元格区域中是引用另一个表格的公式,在该单元格区域中将只有一个日期。 I'm trying to get that one date to populate into cell H12.我试图让那个日期填充到单元格 H12 中。 This is the formula that I have in H12:这是我在 H12 中的公式:

=IF(COUNTA(M4:M18)=1,INDEX(M4:M18,MATCH("*",M4:M18,0)),"") =IF(COUNTA(M4:M18)=1,INDEX(M4:M18,MATCH("*",M4:M18,0)),"")

I've also tried:我也试过:

=IF(COUNTIF(M4:M18,"?")=1,INDEX(M4:M18,MATCH("?",M4:M18,0)),"") =IF(COUNTIF(M4:M18,"?")=1,INDEX(M4:M18,MATCH("?",M4:M18,0)),"")

This formula returns a black cell in H12.此公式返回 H12 中的黑色单元格。 I read a previous post regarding this same issue, but I can't seem to get it to work.我阅读了关于同一问题的先前帖子,但我似乎无法使其正常工作。 The first cell in this range could be empty.此范围内的第一个单元格可能为空。

Any help would be greatly appreciated.任何帮助将不胜感激。

Thanks谢谢

M4:M18 ='Step 2 Triage_Tbl';$Q3 and are formatted as m/d/yy;;"" M4:M18 ='Step 2 Triage_Tbl';$Q3 并被格式化为 m/d/yy;;""

and

OneDate UDF OneDate UDF

In VBE (ALT+F11) insert a module into your worksheet and copy the code into it.在 VBE (ALT+F11) 中将模块插入工作表并将代码复制到其中。

In Excel in cell H12 type =OneDate(M4:M18) .在单元格H12中的 Excel 中输入=OneDate(M4:M18) You might need to format H12 as Date if not already formatted.如果尚未格式化,您可能需要将H12格式化为日期。

Option Explicit

Function OneDate(CheckRange As Range) As Date
    Dim rng As Range
    For Each rng In CheckRange
        If IsDate(rng.Value) Then OneDate = rng.Value: Exit For
    Next
End Function

You might need to adjust the Macro settings for this to work:您可能需要调整宏设置才能使其正常工作:

File > Options > Trust Center > Trust Center Settings > Macro Settings

在此处输入图像描述

To return only one (1) date in a range M4:M18 , try..........要仅返回M4:M18范围内的一 (1) 个日期,请尝试.....

In N2 , enter formula:N2中,输入公式:

=IF(COUNT(M4:M18)=1,INDEX(M4:M18,MATCH(1,INDEX(0+ISNUMBER(M4:M18),0),0)),"")

在此处输入图像描述

Say M4:M18 is completely filled with formulas, but only one of the formulas gives data, the others, null.假设M4:M18完全用公式填充,但只有一个公式给出数据,其他公式为 null。 This will locate the data:这将找到数据:

=MATCH(TRUE,M4:M18<>"",0)

and this will retrieve the data:这将检索数据:

=INDEX(M4:M18,MATCH(TRUE,M4:M18<>"",0))

在此处输入图像描述

This works for text or numbers or dates.这适用于文本或数字或日期。

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

相关问题 如果范围内只有一个单元格有值,如何将单元格范围内的值复制到另一个单元格? - How to copy the value in a range of cells to another cell if only one cell in the range has a value? 将单元格值复制到一系列单元格 - Copy cell value to a range of cells 将值从工作表中的单元格复制到一系列单元格中 - Copy the value from a cell in a worksheet into a range of cells 如果另一个单元格的值为“ x”,则将一系列单元格的格式设置为未锁定 - Format a range of cells as unlocked if another cell has a value of “x” 如果一个单元格等于条件,则查找范围内的单元格将其值复制到另一列 - Find cells within a range if one cell equals a criteria copy its value to another column Excel:仅根据一个单元格的值或公式填充一系列单元格 - Excel: Fill a range of cells with a value or formula depending on only one cell 如果单元格 &lt;= 值,则复制范围 - Copy Range if cell is <= value 根据另一个单元格值更改单元格范围 - Change range of cells base on another cell value 根据另一个单元格的值更新一系列单元格 - Updating a range of cells based on the value of another cell 如果某个范围中的单元格的值为“ x”,则将某个范围的单元格复制并粘贴到另一张工作表中 - If cell in a range has value “x” copy and paste a range of cells into a different sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM