need a VBA for TEXTJOIN FILTER

MMM_84

New Member
Joined
Jan 13, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi,
I'm trying to write a VBA code for the textjoin filter function, but no success. I need unique values from three columns (A, C and D) place into matrix (range D22:E28) based on matching criteria ("Function", "Company" and "Level"). The following function TEXTJOIN(CHAR(10),TRUE, FILTER($A$2:$A$6&CHAR(10)&$C$2:$C$6&CHAR(10)&$D$2:$D$6,$E$2:$E$6&$B$2:$B$6=$C22&E$21,"")) works perfectly, but I'd like to have it automated and appearing in all cells.

Sub Button1 ()
Dim result As String

result = WorksheetFunction.TextJoin(vbNewLine, True, WorksheetFunction.Filter(Range("$A$2:$A$6") & vbNewLine & Range("$C$2:$C$6") & vbNewLine & Range("$D$2:$D$6"), Range("$E$2:$E$6") & Range("$B$2:$B$6") = Range("$C22&E$21"), " "))


Worksheets("result").Cells(5, 22).Value = result
Worksheets("result").Cells(1, 1).Select


End Sub


1701874022477.png



Thanks for help
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try the following instead...

VBA Code:
    Dim result As String

    With ThisWorkbook.Worksheets("Sheet1")
        result = .Evaluate("TEXTJOIN(CHAR(10),TRUE,FILTER($A$2:$A$6&CHAR(10)&$C$2:$C$6&CHAR(10)&$D$2:$D$6,$E$2:$E$6&$B$2:$B$6=$C22&E$21,""""))")
    End With

Change the sheet name accordingly.

Hope this helps!
 
Upvote 0
Try the following instead...

VBA Code:
    Dim result As String

    With ThisWorkbook.Worksheets("Sheet1")
        result = .Evaluate("TEXTJOIN(CHAR(10),TRUE,FILTER($A$2:$A$6&CHAR(10)&$C$2:$C$6&CHAR(10)&$D$2:$D$6,$E$2:$E$6&$B$2:$B$6=$C22&E$21,""""))")
    End With

Change the sheet name accordingly.

Hope this helps!
that works perfectly! Thanks a ton! Would you also advise how to repeat the same formula to other cells (D22,D23 and etc)?
 
Upvote 0
Please post your sample data and outcome as text. Or, better yet, use the xl2BB add-in instead. Data from images can't be copied and pasted into a worksheet for testing.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,226,735
Messages
6,192,733
Members
453,752
Latest member
Austin2222

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