不匹配的行单元格的公式和一列中的显示值
Formula for unmatched row cell and display value in one column
行单元格不匹配并在一列中显示为的公式是什么
附件中提到sheet
工作sheet 以获得结果和 Header 列值
我正在使用这个公式:
=IFERROR(VLOOKUP(A2,A2:M2,1,FALSE),"")
但它在结果列中只显示一个值。
本机工作表公式不能很好地处理字符串连接。即使是正在引入的新字符串函数,例如 TEXTJOIN function¹ and the updated CONCAT function² 也难以进行超出 TEXTJOIN 的 blank/no-blank 参数的条件连接。
这里有一对将执行任务的用户定义函数(又名 UDF)。
Function udfUniqueList(rng As Range, _
Optional delim As String = ",")
Dim str As String, r As Range
'always truncate ranges as parameters to the usedrange
Set rng = Intersect(rng, rng.Parent.UsedRange)
str = rng(1).Value2
For Each r In rng
If Not CBool(InStr(1, delim & str & delim, delim & r.Value2 & delim, vbTextCompare)) Then
str = str & delim & r.Value2
End If
Next r
udfUniqueList = str
End Function
Function udfRogueHeaders(rng As Range, hdr As Range, _
Optional delim As String = ",", _
Optional bBlnks As Boolean = False)
Dim i As Long, bas As String, str As String
'always truncate ranges as parameters to the usedrange
Set rng = Intersect(rng, rng.Parent.UsedRange)
'reshape hdr to be identical to rng
Set hdr = hdr.Resize(rng.Rows.Count, rng.Columns.Count)
bas = rng(1).Value2
For i = 1 To rng.Cells.Count
If (CBool(Len(UCase(rng.Cells(i).Value2))) And Not bBlnks) Or _
bBlnks Then
If UCase(bas) <> UCase(rng.Cells(i).Value2) Then
str = str & IIf(CBool(Len(str)), delim, vbNullString) & _
hdr.Cells(i).Value2
End If
End If
Next i
udfRogueHeaders = str
End Function
在P2:Q2中,
=udfUniqueList(A2:L2)
=udfRogueHeaders(A2:L2, A:L)
¹ TEXTJOIN function 随 Excel 2016 ⁄ Office 365 ⁄ Excel 在线推出。它在早期版本中不可用。
² 具有改进功能的新 CONCAT function for Excel 2016 ⁄ Office 365 ⁄ Excel Online is intended to replace the older CONCATENATE function。
行单元格不匹配并在一列中显示为的公式是什么 附件中提到sheet
工作sheet 以获得结果和 Header 列值
我正在使用这个公式:
=IFERROR(VLOOKUP(A2,A2:M2,1,FALSE),"")
但它在结果列中只显示一个值。
本机工作表公式不能很好地处理字符串连接。即使是正在引入的新字符串函数,例如 TEXTJOIN function¹ and the updated CONCAT function² 也难以进行超出 TEXTJOIN 的 blank/no-blank 参数的条件连接。
这里有一对将执行任务的用户定义函数(又名 UDF)。
Function udfUniqueList(rng As Range, _
Optional delim As String = ",")
Dim str As String, r As Range
'always truncate ranges as parameters to the usedrange
Set rng = Intersect(rng, rng.Parent.UsedRange)
str = rng(1).Value2
For Each r In rng
If Not CBool(InStr(1, delim & str & delim, delim & r.Value2 & delim, vbTextCompare)) Then
str = str & delim & r.Value2
End If
Next r
udfUniqueList = str
End Function
Function udfRogueHeaders(rng As Range, hdr As Range, _
Optional delim As String = ",", _
Optional bBlnks As Boolean = False)
Dim i As Long, bas As String, str As String
'always truncate ranges as parameters to the usedrange
Set rng = Intersect(rng, rng.Parent.UsedRange)
'reshape hdr to be identical to rng
Set hdr = hdr.Resize(rng.Rows.Count, rng.Columns.Count)
bas = rng(1).Value2
For i = 1 To rng.Cells.Count
If (CBool(Len(UCase(rng.Cells(i).Value2))) And Not bBlnks) Or _
bBlnks Then
If UCase(bas) <> UCase(rng.Cells(i).Value2) Then
str = str & IIf(CBool(Len(str)), delim, vbNullString) & _
hdr.Cells(i).Value2
End If
End If
Next i
udfRogueHeaders = str
End Function
在P2:Q2中,
=udfUniqueList(A2:L2)
=udfRogueHeaders(A2:L2, A:L)
¹ TEXTJOIN function 随 Excel 2016 ⁄ Office 365 ⁄ Excel 在线推出。它在早期版本中不可用。
² 具有改进功能的新 CONCAT function for Excel 2016 ⁄ Office 365 ⁄ Excel Online is intended to replace the older CONCATENATE function。