I have a data dump from different application. I want to get unique values from a singular column in the data dump (which has variable length). Once I have the unique values I want them to be called into an .incelldropdown from data validation. I've figured out most of this except for the last part where I get the error:
Runtime Application Error: "1004" Application or object defined error.
See below:
Sub TitleRange()
Dim sheet As Worksheet
Dim LastRow As Long
Dim StartCell As Range
Dim RangeArray As Variant
Worksheets("Raw").Select
Set sheet = Worksheets("Raw")
Set StartCell = Range("A2")
'Find Last Row
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Select Range & load into array
RangeArray = sheet.Range("A2:A" & LastRow).Value
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim i As Long
For i = LBound(RangeArray) To UBound(RangeArray)
d(RangeArray(i, 1)) = 1
Next i
Dim v As Variant
For Each v In d.Keys()
'd.Keys() is a Variant array of the unique values in RangeArray.
'v will iterate through each of them.
Next v
'This code below gives me a problem
Worksheets("PR Offer Sheet").Select
Range("C1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=d.Keys()
.InCellDropdown = True
End With
The debugger says the problem is the d.Keys()
from scripting. However, I've tried to convert into a string using Join (d.Keys(), ",")
and calling that new variable in the data validation which yields same error. I am running this on Excel 2010.
I thought this also might be a problem that the variant array is 2D and it needs to be 1D but that doesn't seem to be the case.