Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing values to worksheet from array

Hi

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Writing values to worksheet from array

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

--
Regards,
Tom Ogilvy


"interstellar" wrote in message
...
Hi

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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Writing values to worksheet from array


MyCell.NumberFormatLocal = "@"
MyCell.Value2 = "10/08/2005"

OR
MyCell.Value="'" & "10/08/2005

--
bighea

-----------------------------------------------------------------------
bighead's Profile: http://www.excelforum.com/member.php...fo&userid=2704
View this thread: http://www.excelforum.com/showthread.php?threadid=46680

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Writing values to worksheet from array

Doh!

Many thanks Tom

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"interstellar" wrote in message
...
Hi

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?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Writing values to worksheet from array

You should be aware that all VBA uses US-style dates (mm/dd/yyyy, not dd/mm/yyyy), no matter what
your settings.

You can switch the day and month like so:

Dim myDate As String
myDate = "8/11/2005"
array(index1, index2) = _
DateValue(Day(DateValue(myDate)) & "/" & _
Month(DateValue(myDate)) & "/" & _
Year(DateValue(myDate)))

MyCell.Value = array(index1, index2)

HTH,
Bernie
MS Excel MVP


"interstellar" wrote in message
...
Hi

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?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Writing values to worksheet from array

Bernie,
Just for information:
cdate will convert the string in accordance with regional settings.

Datevalue won't as I recollect - so, seems to me, your solution would still
produce the wrong result with the ambiguous date string 10/08/2005
Then maybe I am missing something
--
Regards,
Tom Ogilvy

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
You should be aware that all VBA uses US-style dates (mm/dd/yyyy, not

dd/mm/yyyy), no matter what
your settings.

You can switch the day and month like so:

Dim myDate As String
myDate = "8/11/2005"
array(index1, index2) = _
DateValue(Day(DateValue(myDate)) & "/" & _
Month(DateValue(myDate)) & "/" & _
Year(DateValue(myDate)))

MyCell.Value = array(index1, index2)

HTH,
Bernie
MS Excel MVP


"interstellar" wrote in message
...
Hi

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?





  #7   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet Function to Create Array of Size n with values x Through Dial222 Excel Discussion (Misc queries) 1 December 6th 07 11:21 AM
Array Pasted from One Worksheet Converts Null Values to Zeros BK Waas Excel Discussion (Misc queries) 0 November 22nd 06 05:21 PM
(Newbie) Copying values from an array to the worksheet Srdjan Kovacevic[_5_] Excel Programming 1 July 12th 05 03:47 PM
Array of Values from Worksheet Range - What does it 'look' like? Alan Excel Programming 7 July 8th 04 01:06 PM
Writing Array Formulas in VBA Ed Excel Programming 4 January 10th 04 07:27 PM


All times are GMT +1. The time now is 09:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"