Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Array Element question

How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array Element question

Assume a 1 dimensional array

Sub Arr1()
Dim myArray()
Dim num As Long
num = 5
ReDim myArray(0 To num - 1)
For i = 0 To num - 1
myArray(i) = i
Next
lastrow = 20
If UBound(myArray) - LBound(myArray) + 1 < 20 Then _
lastrow = UBound(myArray) - LBound(myArray) + 1
Range("A1:A" & lastrow).Value = Application.Transpose(myArray)
End Sub


If more than 20 values, then only the first 20 values will appear.

--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Array Element question

Many thanks.
Should have said that the array elements need to paste
with a blank row between each element, rather than as a
contiguous 'list'.

I will be pasting them into a sheet where there will be 45+
designated rows. Any current values can be overwritten. I don't want to
insert the values (creating extra rows), just to overwrite the existing
contents.

Looked in Help to see if there is an argument with
Transpose that might be useful....but there doesn't seem
to be a listing for Transpose.

Can I loop through the 20 elements one at a time, and paste each time with
an offset, ....or a better way?

Regards and thanks.

"Tom Ogilvy" wrote in message
...
Assume a 1 dimensional array

Sub Arr1()
Dim myArray()
Dim num As Long
num = 5
ReDim myArray(0 To num - 1)
For i = 0 To num - 1
myArray(i) = i
Next
lastrow = 20
If UBound(myArray) - LBound(myArray) + 1 < 20 Then _
lastrow = UBound(myArray) - LBound(myArray) + 1
Range("A1:A" & lastrow).Value = Application.Transpose(myArray)
End Sub


If more than 20 values, then only the first 20 values will appear.

--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array Element question

Should have said that the array elements need to paste
with a blank row between each element, rather than as a
contiguous 'list'.


That would have been useful.

Dim i as Long, j as Long, k as Long
Dim rng as Range
' set rng to first cell to hold value
set rng = Worksheets("ABC").Range("F32")
i = -1
j = 0
for k = lbound(vArr) to ubound(vArr)
i = i + 2: j = j + 1
rng(i).Value = vArr(k)
if j = 20 then exit for
Next

code is untested, but should represent a feasible approach.

--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
Many thanks.
Should have said that the array elements need to paste
with a blank row between each element, rather than as a
contiguous 'list'.

I will be pasting them into a sheet where there will be 45+
designated rows. Any current values can be overwritten. I don't want to
insert the values (creating extra rows), just to overwrite the existing
contents.

Looked in Help to see if there is an argument with
Transpose that might be useful....but there doesn't seem
to be a listing for Transpose.

Can I loop through the 20 elements one at a time, and paste each time with
an offset, ....or a better way?

Regards and thanks.

"Tom Ogilvy" wrote in message
...
Assume a 1 dimensional array

Sub Arr1()
Dim myArray()
Dim num As Long
num = 5
ReDim myArray(0 To num - 1)
For i = 0 To num - 1
myArray(i) = i
Next
lastrow = 20
If UBound(myArray) - LBound(myArray) + 1 < 20 Then _
lastrow = UBound(myArray) - LBound(myArray) + 1
Range("A1:A" & lastrow).Value = Application.Transpose(myArray)
End Sub


If more than 20 values, then only the first 20 values will appear.

--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Array Element question

Sorry for that omission. Didn't know Transpose.
Ignorantly, I assumed any reply would pull out the
array elements one at a time (and I could then try
to adapt the code).

Thanks for the approach. Will try to develop it.

Regards.

"Tom Ogilvy" wrote in message
...
Should have said that the array elements need to paste
with a blank row between each element, rather than as a
contiguous 'list'.


That would have been useful.

Dim i as Long, j as Long, k as Long
Dim rng as Range
' set rng to first cell to hold value
set rng = Worksheets("ABC").Range("F32")
i = -1
j = 0
for k = lbound(vArr) to ubound(vArr)
i = i + 2: j = j + 1
rng(i).Value = vArr(k)
if j = 20 then exit for
Next

code is untested, but should represent a feasible approach.

--
Regards,
Tom Ogilvy


--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
Many thanks.
Should have said that the array elements need to paste
with a blank row between each element, rather than as a
contiguous 'list'.

I will be pasting them into a sheet where there will be 45+
designated rows. Any current values can be overwritten. I don't want to
insert the values (creating extra rows), just to overwrite the existing
contents.

Looked in Help to see if there is an argument with
Transpose that might be useful....but there doesn't seem
to be a listing for Transpose.

Can I loop through the 20 elements one at a time, and paste each time
with
an offset, ....or a better way?

Regards and thanks.

"Tom Ogilvy" wrote in message
...
Assume a 1 dimensional array

Sub Arr1()
Dim myArray()
Dim num As Long
num = 5
ReDim myArray(0 To num - 1)
For i = 0 To num - 1
myArray(i) = i
Next
lastrow = 20
If UBound(myArray) - LBound(myArray) + 1 < 20 Then _
lastrow = UBound(myArray) - LBound(myArray) + 1
Range("A1:A" & lastrow).Value = Application.Transpose(myArray)
End Sub


If more than 20 values, then only the first 20 values will appear.

--
Regards,
Tom Ogilvy

"S G Booth" wrote in message
...
How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Array Element question

To answer your second question...

This will rename the first worksheet to 'Test'

Sheet1.Name = "Test"


"S G Booth" wrote:

How can I refer to elements in an array?
Say just the 1st 20, and paste the values into
"A1" of the activesheet, please?

What if there were less than 20 elements?

Regards.



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
Counting Array element asingh Excel Worksheet Functions 4 April 12th 10 03:30 PM
Permutations of an array element < to a value Bruce Excel Worksheet Functions 3 January 31st 06 04:00 PM
Array element Andrea[_8_] Excel Programming 5 December 7th 04 08:24 PM
Deleting data and element in a 1D array ExcelMonkey[_124_] Excel Programming 11 May 17th 04 06:29 AM
deleting array element michael Excel Programming 0 December 18th 03 08:55 PM


All times are GMT +1. The time now is 01:58 PM.

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

About Us

"It's about Microsoft Excel"