Data Validation on Table Column with Multiple "Tags" Per Cell, Checked against List

mc-lemons

Board Regular
Joined
Apr 30, 2012
Messages
54
Office Version
  1. 365
Platform
  1. Windows
Hello!

Below is a simplified example, but I'm looking to have a table where one of the columns is for entering "Tags". I would like to be able to enter any number of valid tags from the "Master Tag List" and separate each value by a comma and space as shown below. I figured this could potentially be done with a formula via data validation, but need some help with the formula. So for example, if "Tag 4" or "Tag 5" as shown below in A5 & A6 were entered (or any typo was made), an error message would pop up because those aren't in the Master Tag List.

I am using Microsoft 365, so can use all the nice new fancy formulas and dynamic arrays.

Thanks for your time and consideration!

1713581288546.png
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
If you're open to a VBA solution, why not use a worksheet change event module, coupled with data validation in column A? The following code would go in the worksheet module of the sheet in question (right click the sheet tab name, select View Code and put the code in the blank window that appears). Make as many cells in column A tied via data validation to your existing cells in column D (because it's a table it will expand as you add tag names) as you think you'll ever need. That way, only Tag names listed in column D could ever be added to column A.

The code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Oldvalue As String, Newvalue As String
    Application.EnableEvents = False
    On Error GoTo Exitsub
    If Target.Column = 1 Then
        If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
            GoTo Exitsub
            Else
            If Target.Value = "" Then GoTo Exitsub Else
            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 & ", " & Newvalue
                Else
                Target.Value = Oldvalue
                End If
            End If
        End If
    End If
Exitsub:
    Application.EnableEvents = True
End Sub

Link to demo file: Data validation multiple selections.xlsm
 
Upvote 0
Thanks for taking the time to write the code! However, it doesn't appear to be working how I want. It works if a single tag is entered (A5), but not if I try entering multiple tags separated by a comma (A6), even if they are both valid tags (see below)

Also, I prefer non-VBA most of the time in Excel, largely due to it clearing the undo stack.

1713910235434.png
 
Upvote 0
What you're asking for is not possible with an Excel formula. Excel looks at the content of the entire cell as 1 string.
 
Upvote 0
I did end up finding a solution. I'm sure there's a more efficient way to do it, but below is the formula I came up with. I also had to use to helper columns since table references can't be used in Data Validation. Below is a screenshot and the spreadsheet can be found here.

Formula:
=IF(COUNTIF($F$2#,"<>0")=0,TRUE,IF(SUM(IF(ISNUMBER(XMATCH(TEXTSPLIT(TEXTJOIN(",",,SUBSTITUTE(FILTER($F$2#,$F$2#<>0),", ",",")),,","),$I$2#)),0,1))>0,FALSE,TRUE))

1713910520919.png
 
Upvote 0
Solution
What happens if you enter Tag 2, Tag 3?
 
Upvote 0
It works as expected, aka no validation error. I linked the spreadsheet, so let me know if you have a different experience or get it to break. So far it's working with every test I've tried. I guess the one thing it allows that I'd prefer it didn't, is that duplicates of valid tags are permitted. So you can enter "Tag1, Tag1" without validation error, but otherwise happy with the result.
 
Upvote 0
I didn't test it in Google sheets. Download it in xlsx format and try it in Microsoft Excel
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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