xl2010/xl2013 的 TEXTJOIN 符合条件
TEXTJOIN for xl2010/xl2013 with criteria
我有 2 个工作表。第一个工作表有大约 100 行,但我们只对 Y 列感兴趣。Y 列中的单元格混合了空白单元格 ("")、文本和数字,以及显示 #N/A 的单元格。与图片相似,但更大 data-set.
在第二个工作表中,有一个单元格,我想用 'texts and numbers' 捕获单元格,并在同一单元格内的不同行中显示每条记录(例如,如果有 12 个100 个单元格 'texts and numbers',然后我想在第二个工作表的特定单元格中显示此信息。像这样:
我试过类似的方法,但它似乎只捕获第一行文本(例如标题行):
=IFERROR(INDEX('1Comms'!Y:Y,MATCH(TRUE,'1Comms'!Y:Y<>"",0)),"")
有没有办法也错过标题?
我做错了什么,有什么办法吗?
此 TextJoinIfs user-defined-function(又名 UDF)为 Excel 2003 - 2013 版本提供了基本的 TEXTJOIN 功能,并通过添加可选的错误控制、唯一性、排序和一组简单的条件条件。
此 TextJoinIfs UDF 代码属于 public 模块代码 sheet;例如Book1 - Module1(代码)。
Option Explicit
Public Function TextJoinIfs(delim As String, iOptions As Long, iIgnoreHeaderRows As Long, _
rng As Range, ParamArray pairs()) As Variant
'TEXTJOINIFS - Basic TEXTJOIN functionality for XL2003-XL2013 versions
' Expanded TEXTJOINIFS functionality for all versions
' =TextJoinIfs(<delimiter>, <options>, <header_rows>, <string_range>, [criteria_range1, criteria1], [criteria_range2, criteria2], …)
' OPTIONS
' +2 Include blanks
' +4 Include worksheet errrors
' +8 Unique list
' +16 Sort ascending (cannot be used with 17)
' +17 Sort descending (cannot be used with 16)
If Not CBool(UBound(pairs) Mod 2) Then
TextJoinIfs = CVErr(xlErrValue)
Exit Function
End If
Dim i As Long, j As Long, a As Long, arr As Variant
Dim bIncludeBlanks As Boolean, bIncludeErrors As Boolean, bUniqueList As Boolean
Dim bSorted As Boolean, bDescending As Boolean
bIncludeBlanks = CBool(2 And iOptions)
bIncludeErrors = CBool(4 And iOptions)
bUniqueList = CBool(8 And iOptions)
bSorted = CBool(16 And iOptions)
bDescending = CBool(1 And iOptions)
Set rng = Intersect(rng, rng.Parent.UsedRange.Offset(iIgnoreHeaderRows - rng.Parent.UsedRange.Rows(1).Row + 1, 0))
With rng
ReDim arr(.Cells.Count)
If Not IsMissing(pairs) Then
For i = LBound(pairs) To UBound(pairs) Step 2
Set pairs(i) = pairs(i).Resize(rng.Rows.Count, rng.Columns.Count).Offset(iIgnoreHeaderRows, 0)
Next i
End If
For j = 1 To .Cells.Count
If CBool(Len(.Cells(j).Text)) Or bIncludeBlanks Then
If Not IsError(.Cells(j)) Or bIncludeErrors Then
If IsError(Application.Match(.Cells(j).Text, arr, 0)) Or Not bUniqueList Then
If IsMissing(pairs) Then
arr(a) = .Cells(j).Text
a = a + 1
Else
For i = LBound(pairs) To UBound(pairs) Step 2
If Not CBool(Application.CountIfs(pairs(i).Cells(j), pairs(i + 1))) Then Exit For
Next i
If i > UBound(pairs) Then
arr(a) = .Cells(j).Text
a = a + 1
End If
End If
End If
End If
End If
Next j
End With
ReDim Preserve arr(a - 1)
If bSorted Then
Dim tmp As String
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If CBool(LCase(CStr(arr(i))) < LCase(CStr(arr(j))) And bDescending) Xor _
CBool(LCase(CStr(arr(i))) > LCase(CStr(arr(j))) And Not bDescending) Then
tmp = arr(j): arr(j) = arr(i): arr(i) = tmp
End If
Next j
Next i
End If
TextJoinIfs = Join(arr, delim)
End Function
=TextJoinIfs(<delimiter>, <options>, <header_rows>, <string_range>, [criteria_range1, criteria1], [criteria_range2, criteria2], …)
简单的 TextJoin 操作丢弃空白和错误,只保留唯一的字符串。与换行符 (vbLF) 分隔符连接,但忽略前两行 header 并按升序排序。
=textjoinifs(CHAR(10), 24, 2, A:A)
扩展的 TextJoinIfs 操作丢弃空白和错误,只保留唯一的字符串。用 semi-colon/space 分隔符连接。一组范围和标准的条件。
=textjoinifs("; ", 8, 0, B:B, A:A, A2)
扩展的 TextJoinIfs 操作丢弃空白和错误。与 comma/space 分隔符连接。使用数学比较的多个条件对。
=textjoinifs(", ", 0, 0, B:B, A:A, ">="&D2, A:A, "<="&E2)
非常感谢 Lorem Ipsum Generator 提供示例字符串内容。
我有 2 个工作表。第一个工作表有大约 100 行,但我们只对 Y 列感兴趣。Y 列中的单元格混合了空白单元格 ("")、文本和数字,以及显示 #N/A 的单元格。与图片相似,但更大 data-set.
在第二个工作表中,有一个单元格,我想用 'texts and numbers' 捕获单元格,并在同一单元格内的不同行中显示每条记录(例如,如果有 12 个100 个单元格 'texts and numbers',然后我想在第二个工作表的特定单元格中显示此信息。像这样:
我试过类似的方法,但它似乎只捕获第一行文本(例如标题行):
=IFERROR(INDEX('1Comms'!Y:Y,MATCH(TRUE,'1Comms'!Y:Y<>"",0)),"")
有没有办法也错过标题?
我做错了什么,有什么办法吗?
此 TextJoinIfs user-defined-function(又名 UDF)为 Excel 2003 - 2013 版本提供了基本的 TEXTJOIN 功能,并通过添加可选的错误控制、唯一性、排序和一组简单的条件条件。
此 TextJoinIfs UDF 代码属于 public 模块代码 sheet;例如Book1 - Module1(代码)。
Option Explicit
Public Function TextJoinIfs(delim As String, iOptions As Long, iIgnoreHeaderRows As Long, _
rng As Range, ParamArray pairs()) As Variant
'TEXTJOINIFS - Basic TEXTJOIN functionality for XL2003-XL2013 versions
' Expanded TEXTJOINIFS functionality for all versions
' =TextJoinIfs(<delimiter>, <options>, <header_rows>, <string_range>, [criteria_range1, criteria1], [criteria_range2, criteria2], …)
' OPTIONS
' +2 Include blanks
' +4 Include worksheet errrors
' +8 Unique list
' +16 Sort ascending (cannot be used with 17)
' +17 Sort descending (cannot be used with 16)
If Not CBool(UBound(pairs) Mod 2) Then
TextJoinIfs = CVErr(xlErrValue)
Exit Function
End If
Dim i As Long, j As Long, a As Long, arr As Variant
Dim bIncludeBlanks As Boolean, bIncludeErrors As Boolean, bUniqueList As Boolean
Dim bSorted As Boolean, bDescending As Boolean
bIncludeBlanks = CBool(2 And iOptions)
bIncludeErrors = CBool(4 And iOptions)
bUniqueList = CBool(8 And iOptions)
bSorted = CBool(16 And iOptions)
bDescending = CBool(1 And iOptions)
Set rng = Intersect(rng, rng.Parent.UsedRange.Offset(iIgnoreHeaderRows - rng.Parent.UsedRange.Rows(1).Row + 1, 0))
With rng
ReDim arr(.Cells.Count)
If Not IsMissing(pairs) Then
For i = LBound(pairs) To UBound(pairs) Step 2
Set pairs(i) = pairs(i).Resize(rng.Rows.Count, rng.Columns.Count).Offset(iIgnoreHeaderRows, 0)
Next i
End If
For j = 1 To .Cells.Count
If CBool(Len(.Cells(j).Text)) Or bIncludeBlanks Then
If Not IsError(.Cells(j)) Or bIncludeErrors Then
If IsError(Application.Match(.Cells(j).Text, arr, 0)) Or Not bUniqueList Then
If IsMissing(pairs) Then
arr(a) = .Cells(j).Text
a = a + 1
Else
For i = LBound(pairs) To UBound(pairs) Step 2
If Not CBool(Application.CountIfs(pairs(i).Cells(j), pairs(i + 1))) Then Exit For
Next i
If i > UBound(pairs) Then
arr(a) = .Cells(j).Text
a = a + 1
End If
End If
End If
End If
End If
Next j
End With
ReDim Preserve arr(a - 1)
If bSorted Then
Dim tmp As String
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If CBool(LCase(CStr(arr(i))) < LCase(CStr(arr(j))) And bDescending) Xor _
CBool(LCase(CStr(arr(i))) > LCase(CStr(arr(j))) And Not bDescending) Then
tmp = arr(j): arr(j) = arr(i): arr(i) = tmp
End If
Next j
Next i
End If
TextJoinIfs = Join(arr, delim)
End Function
=TextJoinIfs(<delimiter>, <options>, <header_rows>, <string_range>, [criteria_range1, criteria1], [criteria_range2, criteria2], …)
简单的 TextJoin 操作丢弃空白和错误,只保留唯一的字符串。与换行符 (vbLF) 分隔符连接,但忽略前两行 header 并按升序排序。
=textjoinifs(CHAR(10), 24, 2, A:A)
扩展的 TextJoinIfs 操作丢弃空白和错误,只保留唯一的字符串。用 semi-colon/space 分隔符连接。一组范围和标准的条件。
=textjoinifs("; ", 8, 0, B:B, A:A, A2)
扩展的 TextJoinIfs 操作丢弃空白和错误。与 comma/space 分隔符连接。使用数学比较的多个条件对。
=textjoinifs(", ", 0, 0, B:B, A:A, ">="&D2, A:A, "<="&E2)
非常感谢 Lorem Ipsum Generator 提供示例字符串内容。