Win-XP, Excel 2003
I have a range defined by a name, which is filled by a query. The same named range forms the source of a cell validation (in-cell dropdown list). In m
which is filled by a query
By a query table?
A query table's result range already has a name which is the name (a bit sanitised) of the query table itself (set in the properties dialog). Which means you don't need to redefine anything.
And if you do, then try this code:
Sub asfgsdfg()
Dim n As Name
Set n = ThisWorkbook.Names("LOVL2")
'Or in case of a local name,
'Set n = ThisWorkbook.Worksheets("The worksheet").Names("LOVL2")
ChangeNamedRangeAddress n, n.RefersToRange.CurrentRegion
End Sub
Public Sub ChangeNamedRangeAddress(ByVal n As Name, ByVal NewRange As Range)
n.RefersTo = "='" & Replace(n.RefersToRange.Worksheet.Name, "'", "''") & "'!" & NewRange.Address(True, True, xlA1)
End Sub
EDIT
In regard to the follow-up... Most strange and amusing.
Try using a leading underscore or something?