View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen[_4_] Stephen Bullen[_4_] is offline
external usenet poster
 
Posts: 205
Default Writing values to worksheet from array

Hi Interstellar,

I have a simple!?!? piece of code which grabs data from a 2d array:

MyCell.value=array(index1,index2)

The problem occurs when there's a data - Excel seems to flip the day and
month.

eg where array(index1,index2)="10/08/2005"

MyCell.value="08/10/2005"

I've tried reading the value to a string - the same happens, formatting the
string - the same happens, reading the value to a date -the same happens,
formatting the date - the same happens.

Where am I going wrong?


Excel will always try to interpret the date as a US MDY-order string. Use CDbl
before writing it to the cell:

MyCell.Value = CDbl(SomeDateStringInLocalFormat)

See my web site for (lots) more detail:
http://www.oaltd.co.uk/ExcelProgRef/Ch22/default.htm

Regards

Stephen Bullen
Microsoft MVP - Excel

Professional Excel Development
The most advanced Excel VBA book available
www.oaltd.co.uk/ProExcelDev