[英]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;;""
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
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.