• Status: Solved
• Priority: Medium
• Security: Public
• Views: 153

# importing arrays into excel

This Topic has to do with easy points.

I have created several arrays of vaiable dimension, ie. (1 to 10000, 1 to 6).
I wish to open a new excel spreadsheet and import the arrays into (1 to 6) columns in the spreadsheet, activated by a button on a form.

That is all.....

All I want is a resource with some sample source code.

Thanks
RDXBREWER
0
RDXBrewer
• 3
1 Solution

Commented:
This worked for me:

Option Explicit
Dim ar(1 To 100, 1 To 6) As String 'Change for real purposes.
Dim i As Integer
Dim j As Integer
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Private Sub Command1_Click()

For i = 1 To UBound(ar, 1)
For j = 1 To UBound(ar, 2)
ws.Cells(i, j) = ar(i, j)
Next
Next
xl.Visible = True
End Sub

Set ws = wb.Worksheets(1)

'Create random numbers into array for testing purposes
For i = 1 To UBound(ar, 1)
For j = 1 To UBound(ar, 2)
ar(i, j) = Int(Rnd() * 100)
Next
Next
End Sub

I hope this points you in the right direction

Dabas
0

Commented:
This worked for me:

Option Explicit
Dim ar(1 To 100, 1 To 6) As String 'Change for real purposes.
Dim i As Integer
Dim j As Integer
Dim xl As New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Private Sub Command1_Click()

For i = 1 To UBound(ar, 1)
For j = 1 To UBound(ar, 2)
ws.Cells(i, j) = ar(i, j)
Next
Next
xl.Visible = True
End Sub

Set ws = wb.Worksheets(1)

'Create random numbers into array for testing purposes
For i = 1 To UBound(ar, 1)
For j = 1 To UBound(ar, 2)
ar(i, j) = Int(Rnd() * 100)
Next
Next
End Sub

I hope this points you in the right direction

Dabas
0

Author Commented:
I must not have something set right.

I'm getting an error on:
Dim xl As New Excel.Application

as a user defined type, i.e. not recognizing it and I know I have office installed
0

Commented:
You have to go to Tools -> References and tick Microsoft Excel
0

Commented:
Hi RDXBrewer,
This old question (QID 20560404) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

## Featured Post

• 3
Tackle projects and never again get stuck behind a technical roadblock.