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

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
Asked:
RDXBrewer
  • 3
1 Solution
 
DabasCommented:
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
0
 
DabasCommented:
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
0
 
RDXBrewerAuthor 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
 
DabasCommented:
You have to go to Tools -> References and tick Microsoft Excel
0
 
CleanupPingCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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