Forum Discussion

cswank's avatar
cswank
Copper Contributor
May 21, 2021
Solved

Working with cells that contain multiple values delimited by commas

I have a column where each cell has up to 5 values (from a multiple choice survey), where possible values are one or more of: A, B, C, D, or E,  and any multiple values in one cell are delimited by commas. 

1) How do I filter out only the rows where the cell value contains a particular value such as  "A"?   (same for B, C, D, E)

2) How do I count how many "A" values there are in a column?

 

Thank you!!

Colleen

 

  • cswank 

    1) After turning on Filter, click the filter dropdown arrow in the top cel of the column.

     

    Select Text Filters > Contains...

     

    Enter A (or B, C, ...) in the box.

    Click OK.

     

    2) Use a formula such as

     

    =COUNTIF($A$2:$A$50, "*A*")

     

    The wildcard characters * tell Excel to count cells that contain A with possibly other text.

12 Replies

  • sharmaharsh's avatar
    sharmaharsh
    Copper Contributor
    Working with cells that contain multiple values delimited by commas is common, and it often involves tasks like splitting, combining, or analyzing the values. Here are some common scenarios and techniques for dealing with such cells, assuming you are using a spreadsheet software like Microsoft Excel or Google Sheets:

    Splitting Values:

    Excel:

    You can use the "Text to Columns" feature. Select the column, go to the "Data" tab, and choose "Text to Columns." Select the delimited option, choose comma as the delimiter, and follow the wizard.
    Alternatively, you can use formulas like LEFT, RIGHT, MID, or combination of these to extract individual values.
    Google Sheets:

    You can use the SPLIT function. For example, if A1 contains your comma-separated values, you can use =SPLIT(A1, ",") in another cell to split the values.
    Combining Values:

    Excel:

    You can use the CONCATENATE function to combine values. For example, =CONCATENATE(A1, ", ", B1, ", ", C1).
    In newer versions of Excel, you can also use the TEXTJOIN function.



  • Michael_Yeats's avatar
    Michael_Yeats
    Copper Contributor
    I have used vb to to populate a column with more than one value but need each one to have a comma afterwards so the filter shows them. How do I do this please?
      • Michael_Yeats's avatar
        Michael_Yeats
        Copper Contributor
        Code is below:

        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim Oldvalue As String
        Dim Newvalue As String
        Application.EnableEvents = True
        On Error GoTo Exitsub
        If Target.Address = "$I$" & Target.Row Then
        If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
        GoTo Exitsub
        Else: If Target.Value = "" Then GoTo Exitsub Else
        Application.EnableEvents = False
        Newvalue = Target.Value
        Application.Undo
        Oldvalue = Target.Value
        If Oldvalue = "" Then
        Target.Value = Newvalue
        Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
        Target.Value = Oldvalue & vbNewLine & Newvalue
        Else:
        Target.Value = Oldvalue
        End If
        End If
        End If
        End If
        Application.EnableEvents = True
        Exitsub:
        Application.EnableEvents = True
        End Sub

        The result populates the cells with multiple selections however, when using filter on the column, it wont pick up cells with more than one selection
  • cswank 

    1) After turning on Filter, click the filter dropdown arrow in the top cel of the column.

     

    Select Text Filters > Contains...

     

    Enter A (or B, C, ...) in the box.

    Click OK.

     

    2) Use a formula such as

     

    =COUNTIF($A$2:$A$50, "*A*")

     

    The wildcard characters * tell Excel to count cells that contain A with possibly other text.

Resources