I've created a macro to fill in some data, and it also should put out a dropdown menu in the cell G2 for the list I've created in column O, I've made the range that should be the reference point dynamic. Next I want to name said range and save it under a specific name, and then use that name as reference for the dropdown.
It works for me and some users that need to use that macro, but some (including the head of the department for whom I've made the macro) get error 1004 (Application-defined or Object-defined error) when trying to run the macro
Dim MyRange As Range
rowcounter = Cells(Rows.count, "O").End(xlUp).Row
For x = 1 To rowcounter
If MyRange Is Nothing Then
Set MyRange = Cells(x, "O")
Else
Set MyRange = Union(MyRange, Cells(x, "O"))
End If
Next x
Dim NewFormula1 as string: NewFormula1 = "=" & MyRange
Range("G2").Select
With Selection.Validation
.Delete
.Add _
Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=NewFormula1
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Edit I've changed the code after the suggestion from @VBasic2008, thanks for that btw! Now users get error 13 type mismatch at:
Dim NewFormula1 as string: NewFormula1 = "=" & MyRange
for me and others it still works just like before