Scripting Dictionary help when there is a comma in the string

jscambray

New Member
Joined
Dec 13, 2018
Messages
7
Hello,

I am looking for some assistance in using a Scripting Dictionary to read a column of data and store unique values for output into a list. The problem i am coming across is the Scripting Dictionary is parsing lines in separately when it sees a comma.

For example:

AL - Medical Group, LLC [6239]
CA - Medical Group, LLC [4378]
WA - Medical Group [6792]

Produces an output of:

AL - Medical Group
LLC [6239]
CA - Medical Group
LLC [4378]
WA - Medical Group [6792]

I am looking for the output to not be separated when the Scripting Dictionary sees a comma.

Any help appreciated.

Justin

Code:
'Load dictionary with Practice Name values
j = 1
On Error Resume Next
For i = 2 To dataSheetLastRow
    If Len(dataSheet.Cells(i, "A")) <> 0 Then
        dictionary.Add dataSheet.Cells(i, "A"), j
        j = j + 1
    End If
Next


'Populate List
With dashboardMetricsSheet.Range("B3")
    With .Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(dictionary.Keys(), ",")
    End With
End With
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try
Code:
        Dictionary.Add Replace(Cells(i, "A").Value, ",", ""), j
 
Upvote 0
Thanks for the quick response!

That worked to get them all read into the same line. I could probably deal with that as a solution, however is there a way to get the exact contents of the lines stored (including the commas), so when they are selected from a dropdown, they can be used in formulas and calculations to locate the needed data without having to write additional code to match portions of the strings? I was hoping to store it exactly how it exists in the dataset.

AL - Medical Group, LLC [6239]
CA - Medical Group, LLC [4378]
WA - Medical Group [6792]


Thanks,

Justin
 
Upvote 0
Your best bet would be to remove the commas from the sheet before running your code.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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