View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen Stephen Bullen is offline
external usenet poster
 
Posts: 67
Default Maybe a little off topic

Hi Nicke,

I use intersect to get values from an array to a sheet.
Everything works fine in Excel 97,2000 and XP. But in
Excel 2003 it fails when a number contains a comma as
decimal delimiter. Excel 2003 seems to always use period
as a decimal delimiter even if my national settings says
comma.

Example:

Dim Arr As Variant
ReDim Arr(0, 0)
Arr(0, 0) = "123,345"
Intersect(Range("A1"), Range("A1")) = Arr

This will return "123 345" in Excel 2003 and 123,345 in
all other versions.

Is this a bug?

BTW, i've checked "Use system separators" in the options
dialog.


The first rule of ensuring VBA works globally is to *never* let Excel
interpret strings for you. Always do it yourself. In this case,
ensure that your array contains Doubles for any numbers you want to put
in the sheet, using CDbl(text) if the text uses the system separators
or Val(text) if it uses US separators.

Dim Arr As Variant
ReDim Arr(0, 0)
Arr(0, 0) = CDbl("123,345") 'Comma is the decimal separator
Intersect(Range("A1"), Range("A1")) = Arr

I'm assuming here that the text isn't hard-coded into the application
<g. If it is, always hard-code it using US settings.

The underlying problem of how Excel populates a range from an array has
been 'fixed' in various ways for different data types in a number of
versions. However, I get '123 345' in all versions from '97 onwards on
my machine (with Swedish settings).

For a detailed account of the issues when using Excel in non-US
environments, you might like to read my 'International Issues' chapter
of the "Excel 2002 VBA Programmers Reference".

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk