February 3, 2022

Excel: How to concatenate Table column with delimiter - only visible cells

I have the recurring need to concatenate values in an Excel Table but especially only unfiltered visible cells. (One common use case of mine is to get a list of Jira Issue Keys to easily link to multiple issues)
I explain here to solutions I know and share a VBA macro to do this in one click. 

YouTube Tutorial

Manually with Formula

  • Format as Table. Insert-> (Tables) Table
  • Insert a Column to the Left named 'Selected'
  • Select by marking the selected rows with 1 in the 'Selected' Column
  • Insert another Column e.g. 'KeySelected' with the formula =IF([@Selected],[@Key],"")
  • Concatenated Keys can be calculated with the formula: =TEXTJOIN(", ",TRUE,[KeySelected])

VBA Macro

The key part of the code is the line:

Set rng = tblSelected.DataBodyRange.Columns(cCell.Column - tblSelected.HeaderRowRange.Column + 1)
TableColumnToText = ConvertToText(rng.SpecialCells(xlCellTypeVisible), sDelim)

One can easily implement such a macro to an Excel AddIn Ribbon button. Comment below if you want me to explain how I do this.

See also

Excel: Copy Visible Cells only | Thierry Dalon's Blog

No comments:

Post a Comment