Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default One-D Array to Column Problem

Greetings All,

The following code is *supposed* to take data returned from a database
query, extract one field of data to a 1-D array, and place it in a
column of a worksheet:

PasteRange = RecSet.GetRows
ReDim ReturnVals(0 To (UBound(PasteRange, 2) - 1))
For Index = 0 To UBound(PasteRange, 2) - 1
ReturnVals(Index) = PasteRange(2, Index)
Next
Range("AP7:AP469").Value =
Application.WorksheetFunction.Transpose(ReturnVals )

Stepping through in the VB editor shows that the 1-D array indeed
contains the correct information. The last line, however, always
errors out with "Type Mismatch".

Other info: PasteRange and ReturnVals are both Dim'd variant, and the
ODBC query always returns 462 rows. I'm only using the UBound stuff
so there's fewer lines of code to change if the database changes.

Any ideas?

-John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default One-D Array to Column Problem

John,

I do not know why you are getting the error in the Transpose line.
However, you do not need to use Transpose as you can write the PasteRange
values into ReturnVals and eliminate the need to transpose it.
By the way Range("AP7:AP469") has 463 rows not 462.
Try something like...
'----------------------------
Sub TestArray()
Dim PasteRange As Variant
Dim ReturnVals As Variant
Dim Index As Long

PasteRange = Array(11, 2, 3, 4, 5, 6, 7, 88)
ReDim ReturnVals(0 To UBound(PasteRange), 1 To 1)

For Index = 0 To UBound(PasteRange)
ReturnVals(Index, 1) = PasteRange(Index)
Next

Range("AP7:AP14").Value = ReturnVals
Erase ReturnVals
End Sub
'-------------------------------------------

Regards,
Jim Cone
San Francisco, CA

"John" wrote in message
om...
Greetings All,
The following code is *supposed* to take data returned from a database
query, extract one field of data to a 1-D array, and place it in a
column of a worksheet:
PasteRange = RecSet.GetRows
ReDim ReturnVals(0 To (UBound(PasteRange, 2) - 1))
For Index = 0 To UBound(PasteRange, 2) - 1
ReturnVals(Index) = PasteRange(2, Index)
Next
Range("AP7:AP469").Value =
Application.WorksheetFunction.Transpose(ReturnVals )
Stepping through in the VB editor shows that the 1-D array indeed
contains the correct information. The last line, however, always
errors out with "Type Mismatch".
Other info: PasteRange and ReturnVals are both Dim'd variant, and the
ODBC query always returns 462 rows. I'm only using the UBound stuff
so there's fewer lines of code to change if the database changes.
Any ideas?
-John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default One-D Array to Column Problem

"Jim Cone" wrote in message ...
John,

I do not know why you are getting the error in the Transpose line.
However, you do not need to use Transpose as you can write the PasteRange
values into ReturnVals and eliminate the need to transpose it.
By the way Range("AP7:AP469") has 463 rows not 462.
Try something like...


Thanks Jim! Copying the needed data into a 2-d array worked out great!

-John
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
3D Array Problem sgl Excel Worksheet Functions 2 July 6th 09 06:46 AM
COLUMN() problem with array formula ejack Excel Worksheet Functions 0 April 24th 09 07:05 AM
How to manipulate an 2D Array into a Column Array? Joe Excel Discussion (Misc queries) 3 April 16th 07 06:30 PM
Array problem - TIA S Davis Excel Worksheet Functions 9 November 7th 06 02:22 AM
Array Problem Scott Excel Discussion (Misc queries) 4 May 9th 06 05:22 PM


All times are GMT +1. The time now is 09:45 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"