How to concatenate only visible cells in Excel?
If you have a list of filtered data, now, you just need to concatenate only the visible cells and ignore the hidden cells to get the following combined result. How could you finish this task quickly and easily in Excel?
Concatenate only visible cell values into one cell with VBA code
Concatenate only visible cell values into one cell with VBA code
You can create a User Defined Function to solve this job, please do with the following steps:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Concatenate only visible cell values:
Private Function ConcatenateVisible(xRg As Variant, sptChar As String)
'Updateby Extendoffice
Dim rg As Range
For Each rg In xRg
If (rg.EntireRow.Hidden = False) And (rg.EntireColumn.Hidden = False) Then
ConcatenateVisible = ConcatenateVisible & rg.Value & sptChar
End If
Next
ConcatenateVisible = Left(ConcatenateVisible, Len(ConcatenateVisible) - Len(sptChar))
End Function
3. Then save and close this code, go back to the worksheet, and enter this formula: =concatenatevisible(B2:B10,"-") (B2:B10 is the filtered data range you want to combine, “-” is the separator to separate the combined values, you can change them to your need.) into a blank cell where you want to locate the combined result, and then press Enter key to get the result. See screenshot:
Note: With this User Defined Function, the combined result will be changed with your filtered data dynamically, for example, if you filter the Product of KTO, your combined result will be changed to the new filtered data. See screenshot:
Best Office Productivity Tools
Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel
Kutools for Excel boasts over 300 features, ensuring that what you need is just a click away...
Supports Office/Excel 2007-2021 & newer, including 365 | Available in 44 languages | Enjoy a full-featured 30-day free trial.
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
