VBA code for selecting multiple items in a single cell pulled from a data validation list

julesmck

New Member
Joined
May 21, 2016
Messages
1
Hi, I'm new to Excel and I'm stumped. I've searched this site and elsewhere trying to find an answer to my question but I haven't had any luck finding one I can understand. :)

Here's the problem:


I'm creating an inventory of all the documentation we have about a product (in case it helps, I've uploaded the workbook I'm trying to get to work here). I'm trying to capture what each document is about by associating if with one or more subjects - for example, a document about uploading documents might contain information about 'metadata,' mandatory 'property fields' and the act of 'uploading' itself. I'd like to be able to associate a single document with all three of those subjects by selecting each of them in a single cell (the values are pulled from a data validation list in another spreadsheet called 'Subject totals.')

Can anyone tell me how to:



  • Set up the workbook so that I can select multiple values using checkboxes from a single cell
  • Set up COUNTIF so that it retrieves an accurate count of all the documents associated with a particular subject (in the example above, the document about uploading documents would count for three subjects: 'metadata,' 'property fields' and 'uploading' subjects).

To solve the first problem, I tried pasting the following code into the workbook, but nothing happened:


Private Sub Worksheet_Change(ByVal Target As Range)


Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler


On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler


If rngDV Is Nothing Then GoTo exitHandler


If Intersect(Target, rngDV) Is Nothing Then


Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then

Else
If newVal = "" Then

Else
Target.Value = oldVal _
& ", " & newVal


End If
End If
End If


exitHandler:
Application.EnableEvents = True
End Sub

Any guidance would be very much appreciated. Thank you!!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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