Excel VBA behaves different in different languages

后端 未结 1 954
礼貌的吻别
礼貌的吻别 2021-01-29 00:15

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

相关标签:
1条回答
  • 2021-01-29 00:53

    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?

    0 讨论(0)
提交回复
热议问题