Link to home
Start Free TrialLog in
Avatar of RDXBrewer
RDXBrewer

asked on

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
Avatar of Dabas
Dabas
Flag of Australia image

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

Private Sub Form_Load()
Set wb = xl.Workbooks.Add
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
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

Private Sub Form_Load()
Set wb = xl.Workbooks.Add
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
Avatar of RDXBrewer
RDXBrewer

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.