tags:

views:

48

answers:

1

Hello All

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 my VBA this range is accessed via a range object named LOVL2.

Each time the range is re-filled by the query, its name is redefined to include all rows I obtained through the query. This is done with statement

LOVL2.CurrentRegion.Name = LOVL2.Name.Name

the statement works fine as long as MS Office language is set to English, but the statement fails when MS office language is set to French .... I get Error 1004 "Invalid Name"

Anyone got an idea what is causing this only when MS Office language is set to FRENCH but not while in ENGLISH? (maybe problem with ";" vs "," within the object ??)

Thanks in advance MikeD


edit 12-Aug-2010

the REAL root cause is clear now:

the range's name is "L2PoP" which in the ENGLISH version is recognized as a valid name for a range - in that you can go to any empty sheet, select a range and name it "L2PoP".

Set your user language to FRENCH, go to any empty sheet, select a range and name it "L2PoP", and you get an error saying "Nom non valide".

so the real curing action is to give a different name to the range which is accepted by both French and English

I can only speculate about what is causing this, it may have to do with the fact that the first 2 characters look like a cell address, on the other hand "A1PoP " is a valid name, whereas "L2Foo" and "L1Foo" are invalid.

strange, but .....

A: 

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?

GSerg
@GSerg: no it is not filled by a query table, but by VBA code that runs when a certain cell is changed; e.g. you enter a country name in A1 (or select from in-cell drop down), and on that change the LOV (list of values) for B1 is recalculated by extracting from a hidden table all resources available in the selected country .
MikeD
Then use the code :)
GSerg
sorry for the delay .... was on vacation; A naked test of your code in an empty sheet works well, even when called thru an event trigger, but frustrating: n.RefersTo brings the same "Nom non valide" in French while it works perfect in English in my application (which also originates this from within an event trigger). I still have no clue where the root cause is, but I will accept your answer anyway ... thanks
MikeD
@GSerg ... thanks again, your code got implemented because it's prettier than mine; and see addendum to my question
MikeD
Ah, the joys of Excel. Just keep poking it, eventually you'll find the right place to poke. Try the underscore :)
GSerg
yeep ... leading underscore would have done ... well I finally chose to rename that range to PoP_L2. Lesson learned for multi-language implementations: test your range names in all languages by trying to jump on them
MikeD