Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to write a single dimension array into an excel column quickly using VBA

Posted on 2013-06-04
4
Medium Priority
?
388 Views
Last Modified: 2013-06-05
Hi Experts, I think this an easy one, but I'm having trouble figuring it out... I have a one dimension array with about 500,000 values that I need to dump into an excel column quickly.  I'm currently using the code:
For x = 1 To UBound(N_Data)
        Cells(x + 1, Last_Col) = N_Data(x)
Next x

Open in new window

Unfortunately this is very slow.  When I try to simply select the range and set the value equal to my data i.e.:
Range(Cells(2,Last_Col),Cells(Ubound(N_Data)+2),Last_Col)) = N_Data

Open in new window

it dumps blank values.  I think this is because the values in my array need to be transposed...
0
Comment
Question by:JamesCbury
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 400 total points
ID: 39221234
You need to transpose the array

Dim xdata(9) As Integer

xdata(5) = 5

Range("a1:a10") = Application.Transpose(xdata)

puts a column of zeroes with row 6 = 5 (array is zero based)
0
 

Author Comment

by:JamesCbury
ID: 39222153
Thanks, that seems like it should work, but when I try to apply it I keep getting a Run time error "13" Type Mismatch...  any thoughts?

Range(Cells(2, Last_Col), Cells(UBound(N_Data) + 1, Last_Col)) = Application.Transpose(N_Data)

Open in new window

0
 
LVL 46

Accepted Solution

by:
aikimark earned 1200 total points
ID: 39222318
See my Fast Data Push to Excel article:
http://www.experts-exchange.com/A_2253.html

You need to create a 2D array, not a 1D (vector) data structure.
0
 

Author Comment

by:JamesCbury
ID: 39222669
Perfect - that did the trick.  I added a dimension to my array
ReDim N_Data(UBound(R_Data), 1)

Open in new window

Loaded my data into the "0" dimension (starting in the "0" position)
For x = 1 To UBound(R_Data, 1)
     N_Data(x - 1, 0) = 'insert calculated value here
Next x

Open in new window

Then bulk-wrote the results
Last_Col = Cells(1, 100).End(xlToLeft).Column
Range(Cells(2, Last_Col), Cells(UBound(N_Data, 1) + 1, Last_Col)) = N_Data

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question