Here is the code I am using
briefly - i m reading the xl sheet to determine the number of records so that I can use a progress bar, then I am reading the xl sheet to derive information from selected rows and then populating the arrays in the sub.
The excel file I am accessing has about 10 worksheets. The one I am reading has about 50,000 rows. In total uncompressed the file is about 30 megabytes.
Dim Synd(5000) As String
Dim Year(5000) As Integer
Dim Ccy(5000) As String
Dim SDate(5000) As Date
Dim Amt(5000) As Double
Dim Mtc(5000) As String
Dim ArrCnt As Long
Dim cmatch As Long
Dim Totalmm1 As Long
Dim Totalmm2 As Long
Dim totxlrecs As Long
Dim cnx As New ADODB.Connection
Dim RS1 As ADODB.Recordset
Dim SQL1 As String
Dim ExcelApp As Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Dim ARow As Long
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkbook = ExcelApp.Workbooks.Open("CashBook")
ExcelApp.Visible = False
Set ExcelSheet = ExcelWorkbook.Worksheets("WS")
totxlrecs = 0
ArrCnt = 0
'
' get a count of records required
'
Lp1:
totxlrecs = totxlrecs + 1
If Trim(ExcelSheet.Cells((totxlrecs + 7), 1).Value) = "" Then ' finished reading XL
GoTo lpz
End If
GoTo Lp1
lpz:
ProgressBar1.Visible = True
ProgressBar1.Max = totxlrecs
ARow = 7
LoopA:
ARow = ARow + 1
ProgressBar1.Value = ProgressBar1.Value + 1
ProgressBar1.Refresh
End If
If Trim(ExcelSheet.Cells(ARow, 1).Value) = "" Then ' finished reading XL
GoTo LoopAEnd
End If
If Trim(ExcelSheet.Cells(ARow, 10).Value) <> "755" Then 'not reqd charge type, ignore
GoTo LoopA
End If
ArrCnt = ArrCnt + 1
Amt(ArrCnt) = ExcelSheet.Cells(ARow, 9).Value
Synd(ArrCnt) = ExcelSheet.Cells(ARow, 1).Value
Year(ArrCnt) = ExcelSheet.Cells(ARow, 5).Value
Ccy(ArrCnt) = ExcelSheet.Cells(ARow, 3).Value
SDate(ArrCnt) = ExcelSheet.Cells(ARow, 2).Value
GoTo LoopA
LoopAEnd:
GoTo Terminate
ErrorHandler1:
Select Case Err.Number
Case Else
MsgBox (Err.Number & " - " & Err.Description)
End Select
Terminate:
ExcelWorkbook.Close savechanges:=False
ExcelApp.Quit
Set ExcelApp = Nothing
Set ExcelWorkbook = Nothing
Set ExcelSheet = Nothing