Concatenate Visible

JJabra

New Member
Joined
Aug 19, 2019
Messages
37
Hi,

I am looking to write a formula that will include into one cell all the values that are visible in column A after filtering. Looking online I have only been able to find the below;

VBA Code:
Public Function ConcatenateVisible(rng As Variant, seperator As String, Optional IGNORE_EMPTY As Boolean = False)
    For Each cll In rng
        If cll.EntireRow.Hidden = False And Not (IsEmpty(cll) And IGNORE_EMPTY) Then _
            ConcatenateVisible = ConcatenateVisible & cll.Value & seperator
    Next
    ConcatenateVisible = Left(ConcatenateVisible, Len(ConcatenateVisible) - Len(seperator))
End Function

however when I now try to use the ConcatenateVisible formula it brings a #NAME? error.

Please can somebody advise of another way to do this or advise how to make the current macro/formula work?

Thanks in advance!
 
The ConcatenateVisible is in the body, Cell "AB12" the email is going to a work inbox to notify which customers need to have emails sent to them via post.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
i see.
I have tested out the code with your concate UDF and do not get an error

1576672521331.png
 
Upvote 0
I have noticed that the issue seems to be that I have a button that filters the table and then sends the email, however when the table is filtered, the ConcatenateVisible returns #VALUE!. However when I go on to the cell and press enter the error goes and I can then run the macro to send the email.

Do you know of any way in which this can work without me having to manually fix the value error?
 
Upvote 0
I can't replicate the problem, possible application.volatile would work.

VBA Code:
Public Function ConcatenateVisible(rng As Variant, seperator As String, Optional IGNORE_EMPTY As Boolean = False)
    Application.Volatile
    For Each cll In rng
        If cll.EntireRow.Hidden = False And Not (IsEmpty(cll) And IGNORE_EMPTY) Then _
           ConcatenateVisible = ConcatenateVisible & cll.Value & seperator
    Next
    ConcatenateVisible = Left(ConcatenateVisible, Len(ConcatenateVisible) - Len(seperator))
End Function
 
Upvote 0
That didn't stop me from getting the #Value! issue when filtering the table, any other Ideas as to why this happens?

Also is there a way to stop the comma appearing on empty rows? as I have set the list to 500 rows because the size of the extract used to populate the table can vary daily.
 
Upvote 0
I have managed to fix the issues with the commas by setting the reference to the column in the table, however I am still having issues with the ConcatenateVisible returning a #Value! error when I run my autofilter macro.

This is the last issue I have. Any help would be greatly appreciated
 
Upvote 0
Ignore empty may be dimmed as a string, not true/false
When I enter strings to ignore it does

Code:
Public Function ConcatenateVisible(rng As Variant, seperator As String, Optional IGNORE_EMPTY As String)
    Application.Volatile
  
    For Each cll In rng
        If cll.EntireRow.Hidden = False Then
            If Not IsEmpty(cll) Then
                If cll <> IGNORE_EMPTY Then
                    ConcatenateVisible = ConcatenateVisible & cll.Value & seperator
                End If
            End If
        End If
    Next
    ConcatenateVisible = Left(ConcatenateVisible, Len(ConcatenateVisible) - Len(seperator))
End Function

Here i told it to ignore g and it did
1576757954554.png
 
Last edited:
Upvote 0
Back to one if line
Code:
Public Function ConcatenateVisible(rng As Variant, seperator As String, Optional IGNORE_EMPTY As String)
    Application.Volatile
    For Each cll In rng
        If cll.EntireRow.Hidden = False And Not IsEmpty(cll) And cll <> IGNORE_EMPTY Then _
                                                             ConcatenateVisible = ConcatenateVisible & cll.Value & seperator
    Next
    ConcatenateVisible = Left(ConcatenateVisible, Len(ConcatenateVisible) - Len(seperator))
End Function
 
Upvote 0
sorry, I'm not sure I fully understand, I wouldnt need to miss out certain entries, however when running the below macros to filter the data set to customers that will need to be contacted it comes up with a value! error

VBA Code:
Sub Escalations()
    
    Dim sht As Worksheet
    Set sht = Worksheets("Extract")

    With sht.Range("C1").CurrentRegion
        .AutoFilter
        .AutoFilter Field:=3, Criteria1:="<" & CLng(Date - 56)
        
    End With
End Sub

Sub LetterSent()
    
    Dim lo As ListObject
    Dim iCol As Long

    Set lo = Sheet2.ListObjects(1)
    iCol = lo.ListColumns("Date Of Eight Week Letter Sent").Index
    lo.Range.AutoFilter Field:=iCol, Criteria1:="="
    
End Sub

Sub Resolved()
    
    Dim lo As ListObject
    Dim iCol As Long

    Set lo = Sheet2.ListObjects(1)
    iCol = lo.ListColumns("Resolved").Index
    lo.Range.AutoFilter Field:=iCol, Criteria1:="N"
    
End Sub

Sub Ombudsman()
    
    Dim lo As ListObject
    Dim iCol As Long

    Set lo = Sheet2.ListObjects(1)
    iCol = lo.ListColumns("RAISED TO OMBUDSMAN").Index
    lo.Range.AutoFilter Field:=iCol, Criteria1:="N"
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top