Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to write data in array to range on worksheet

Hello Again,

And thanks,

I am trying to write strings from an array to a range on a worksheet.
I must be missing something.

the array is dynamic and I use ReDim Preserve to load the contents.
I have 6 strings in the array. I want to write the data in one
column.

Code snippet:
Dim SheetsProcessed as Range
Dim i as Integer

(the array is set in a different module, and marked as Public
sheetsArray() as Variant"

'displays list of sheets processed and evaluated
Set SheetsProcessed = Range("K2", "K" & UBound(sheetsArray)+1)

SheetsProcessed.Name = "processed"
Range("processed").Value = sheetsArray ' this writes only the first
array element

For i = LBound(sheetsArray) To UBound(sheetsArray)
Range("K" & 2 + (i + 1)).Value = sheetsArray(i) ' this writes
each
value in the cell
Next i

The line above Range("processed").value = sheetsArray places the
first
element in the array in 6 cells on the worksheet.
If I change the line to: SheetsProcessed.Value = sheetsArray, I get
the same result as the Range("processed") line above.

I must be missing something here

Thanks,

eholz1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default How to write data in array to range on worksheet

On Jan 30, 9:46*am, eholz1 wrote:
Hello Again,

And thanks,

I am trying to write strings from an array to a range on a worksheet.
I must be missing something.

the array is dynamic and I use ReDim Preserve to load the contents.
I have 6 strings in the array. *I want to write the data in one
column.

Code snippet:
Dim SheetsProcessed as Range
Dim i as Integer

(the array is set in a different module, and marked as Public
sheetsArray() as Variant"

*'displays list of sheets processed and evaluated
* Set SheetsProcessed = Range("K2", "K" & UBound(sheetsArray)+1)

* SheetsProcessed.Name = "processed"
* Range("processed").Value = sheetsArray ' this writes only the first
array element

* For i = LBound(sheetsArray) To UBound(sheetsArray)
* * Range("K" & 2 + (i + 1)).Value = sheetsArray(i) ' this writes
each
value in the cell
* Next i

The line above Range("processed").value = sheetsArray places the
first
element in the array in 6 cells on the worksheet.
If I change the line to: SheetsProcessed.Value = sheetsArray, I get
the same result as the Range("processed") line above.

I must be missing something here

Thanks,

eholz1


Hello All,

Sorry I found the answer in THIS group by searching!

range = Application.Transpose(array)

But.... not sure WHY this works? Is it because it is a single column
and not a range with something like:
Range("A1:F6") ??

thanks again,

eholz1
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
How to write an array to a range without looping Andy Excel Worksheet Functions 3 April 27th 11 12:52 PM
Write data inthe worksheet / array Robert[_33_] Excel Programming 2 June 10th 07 01:43 PM
Write from variant array into range Bharath Rajamani Excel Programming 1 May 9th 07 11:24 AM
Write 3d array to range [email protected] Excel Programming 2 December 31st 06 09:47 AM
write array to range muster Excel Programming 5 June 22nd 06 11:41 PM


All times are GMT +1. The time now is 07:20 AM.

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"