Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA仅连接筛选列的可见单元格。包括测试代码_Vba_Excel_Concatenation - Fatal编程技术网

Excel VBA仅连接筛选列的可见单元格。包括测试代码

Excel VBA仅连接筛选列的可见单元格。包括测试代码,vba,excel,concatenation,Vba,Excel,Concatenation,大家好 我试图将一个过滤列连接到一个用逗号分隔的单元格中。我对编码知之甚少,这些代码是别人搜索数小时后提供的 到目前为止,此函数可以工作,但也可以连接不可见的过滤出的单元格: Function test1(myRange As Range) Dim aOutput For Each entry In myRange If Not IsEmpty(entry.Value) Then aOutput = aOutput & entry.Value & ", "

大家好

我试图将一个过滤列连接到一个用逗号分隔的单元格中。我对编码知之甚少,这些代码是别人搜索数小时后提供的

到目前为止,此函数可以工作,但也可以连接不可见的过滤出的单元格:

Function test1(myRange As Range)
Dim aOutput
For Each entry In myRange
    If Not IsEmpty(entry.Value) Then
        aOutput = aOutput & entry.Value & ", "
    End If
Next
test1 = Left(aOutput, Len(aOutput) - 1)
End Function
这一个也可以从范围中删除重复项,但存在相同的问题:

Function test2(ByRef rRng As Range, Optional ByVal sDelim As String = ", ") As String
Dim oDict As Object
Dim rCell As Range
Dim sTxt As String
Set oDict = CreateObject("Scripting.Dictionary")
With oDict
    For Each rCell In rRng
        If .Exists(rCell.Text) Then
            'Do nothing
        Else
            .Add rCell.Text, rCell.Text
            sTxt = sTxt & sDelim & rCell.Text
        End If
    Next rCell
End With
    test2 = Mid(sTxt, Len(sDelim) + 1)
End Function
是否可以更改这两个函数以忽略列中不可见的、过滤掉的单元格

谢谢你的阅读

布莱恩

考虑一下:

Public Function test1(myRange As Range)
    Dim aOutput As String, entry As Range
    For Each entry In myRange
        If entry.EntireRow.Hidden = False Then
            aOutput = aOutput & entry.Value & ", "
        End If
    Next
    test1 = Left(aOutput, Len(aOutput) - 1)
End Function

当然-在函数内部和任何可执行指令之前,声明一个新变量myRangeVisible,如下所示:

Dim myRangeVisible as Range
并将其设置为仅包含myRange内可见的细胞

Set myRangeVisible = myRange.SpecialCells(xlCellTypeVisible)

并将此范围用作函数代码中所有操作的源范围

谢谢,我将尝试使用此帮助更改函数@用户2284877您将使用
集合
删除重复项