Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions

D.W. Simpson and Company -- Actuary Salary Surveys
Pension, Life, Health and Investment Actuarial Jobs

Property and Casualty Actuarial Jobs   Registration Form


Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2005, 11:49 AM
SamChevre's Avatar
SamChevre SamChevre is offline
Member
 
Join Date: Jan 2003
Location: Virginia
Posts: 2,141
Default Manipulating Arrays in VBA

OK, I'm working on the Access-Excel problem I mentioned in this thread.

I need to transpose a large array (about 15000x2), so it will paste into Excel correctly. I'm using this code to get the array:

Code:
Set qdf = CurrentDb().QueryDefs("Query1")
Set recSummary = qdf.OpenRecordset
recSummary.MoveLast
recSummary.MoveFirst
varArray = recSummary.GetRows(recSummary.RecordCount)
In Access, it is 10 columns, 1000 rows. I want it to paste into Excel the same way. If I do
Code:
objExcel.Range("A1").Resize(intRows + 1, intFields + 1).Value = varArray
it pastes in as 10 rows, 1000 columns.
The array is too big to transpose using the Transpose function.

Any suggestions?
__________________
Liberals tend to view themselves as live-and-let-live people.... We’re the nice guys. We believe in tolerance, diversity, and letting people be what they have to be. It’s hard for us to credit the idea that someone could be afraid of us.

Someone is. And for good reasons. Understanding that uncomfortable fact is the first step towards grasping what has been going on in this country’s politics for the last quarter century.
Red Family, Blue Family

Last edited by SamChevre; 12-08-2005 at 02:24 PM..
Reply With Quote
  #2  
Old 12-08-2005, 01:27 PM
krank's Avatar
krank krank is offline
Member
 
Join Date: Feb 2004
Location: Stalking the Wiggles
Posts: 5,683
Default

why not use rangeVar.CopyFromRecordset recordsetName
Reply With Quote
  #3  
Old 12-08-2005, 01:49 PM
MNBridge's Avatar
MNBridge MNBridge is offline
Site Supporter
Site Supporter
 
Join Date: Jan 2002
Posts: 8,377
Default

I know ZERO about VBA for Access.

But to transpose in Excel you could

Dim A ( 10000,10)
Dim B ( 10, 10000)

For X = 1 to 10000
For Y = 1 to 10
Set B(Y, X) = A.cells (X,Y)
Next Y
Next X
__________________
Looks like the parastie is going to have to find another life to go after.

He sucked all the enjoyment of visting this place out of me.
Reply With Quote
  #4  
Old 12-08-2005, 02:22 PM
SamChevre's Avatar
SamChevre SamChevre is offline
Member
 
Join Date: Jan 2003
Location: Virginia
Posts: 2,141
Default

Quote:
Originally Posted by MNBridge
I know ZERO about VBA for Access.

But to transpose in Excel you could

Dim A ( 10000,10)
Dim B ( 10, 10000)

For X = 1 to 10000
For Y = 1 to 10
Set B(Y, X) = A.cells (X,Y)
Next Y
Next X
That will work (that's basically the method I'm using now). The problem is that when the array is too large to fit in RAM (mine is), it's insanely slow, since it has to call data off the disk for every loop.
__________________
Liberals tend to view themselves as live-and-let-live people.... We’re the nice guys. We believe in tolerance, diversity, and letting people be what they have to be. It’s hard for us to credit the idea that someone could be afraid of us.

Someone is. And for good reasons. Understanding that uncomfortable fact is the first step towards grasping what has been going on in this country’s politics for the last quarter century.
Red Family, Blue Family
Reply With Quote
  #5  
Old 12-08-2005, 02:23 PM
SamChevre's Avatar
SamChevre SamChevre is offline
Member
 
Join Date: Jan 2003
Location: Virginia
Posts: 2,141
Default

Quote:
Originally Posted by krank
why not use rangeVar.CopyFromRecordset recordsetName
I get the error "Class does not support Automation". Any clue what's wrong?
__________________
Liberals tend to view themselves as live-and-let-live people.... We’re the nice guys. We believe in tolerance, diversity, and letting people be what they have to be. It’s hard for us to credit the idea that someone could be afraid of us.

Someone is. And for good reasons. Understanding that uncomfortable fact is the first step towards grasping what has been going on in this country’s politics for the last quarter century.
Red Family, Blue Family
Reply With Quote
  #6  
Old 12-09-2005, 09:10 AM
krank's Avatar
krank krank is offline
Member
 
Join Date: Feb 2004
Location: Stalking the Wiggles
Posts: 5,683
Default

Quote:
Originally Posted by SamChevre
I get the error "Class does not support Automation". Any clue what's wrong?

so your line of code looked like:

objExcel.Range("A1").CopyFromRecordset recSummary

this caused a problem?
Reply With Quote
  #7  
Old 12-09-2005, 09:32 AM
SamChevre's Avatar
SamChevre SamChevre is offline
Member
 
Join Date: Jan 2003
Location: Virginia
Posts: 2,141
Default

Quote:
Originally Posted by krank
so your line of code looked like:

objExcel.Range("A1").CopyFromRecordset recSummary

this caused a problem?
Yes, the relevant code snippets look like this:

Code:
Dim objExcel As New Excel.Application
Dim qdf As QueryDef
Dim recSummary As Recordset

objExcel.Workbooks.Open "C:\SamChevre.xls"
Set qdf = CurrentDb().QueryDefs("Query1")
Set recSummary = qdf.OpenRecordset
objExcel.Workbooks("SamChevre.xls").Sheets("Data").Activate
objExcel.Sheets("Data").Range("A1").CopyFromRecordset (recSummary)
__________________
Liberals tend to view themselves as live-and-let-live people.... We’re the nice guys. We believe in tolerance, diversity, and letting people be what they have to be. It’s hard for us to credit the idea that someone could be afraid of us.

Someone is. And for good reasons. Understanding that uncomfortable fact is the first step towards grasping what has been going on in this country’s politics for the last quarter century.
Red Family, Blue Family
Reply With Quote
  #8  
Old 12-09-2005, 11:41 AM
Old Actuary Old Actuary is offline
Member
 
Join Date: Sep 2001
Posts: 402
Default

Theres' a 256 column limit in Excel. Therefore, you can't squeeze 1000 columns into one sheet, no matter what macro you use.
Reply With Quote
  #9  
Old 12-12-2005, 12:17 AM
2.718281828's Avatar
2.718281828 2.718281828 is offline
Member
 
Join Date: May 2005
Posts: 176
Default

Yes, you cannot go beyond 256 columns.... But I'm sure our poster knows this.
Why don't you find out what the max number of args are for the Transpose function is.
Break your array into piece so that the transpose function takes it. Then make a program that recombines your arrays at the end. It will probably be the fasted way. Also, the loop in the previous post would be slow since it access the worksheet 100,000 times. You want to do everything in VBA first then put it in the worksheet. The less you access the worksheet during a procedure the better.
Reply With Quote
  #10  
Old 12-12-2005, 12:55 PM
Peter Lemonjello's Avatar
Peter Lemonjello Peter Lemonjello is offline
Member
 
Join Date: May 2005
Posts: 323
Default

Doesn't the new version of Excel support more than 256 columns? Perhaps the poster has the latest and greatest.

Me? I'm stuck in 2000.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 05:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.28484 seconds with 7 queries