Hi,
I have a VBA program for a large file, which works correctly but is slow.
I searching the internet I have see that working off an array vs. the worksheet drastically improves performace. I began converting my code to load my data into an array but am running into a problem with a couple code lines where I was using Function.Match to pull row numbers to create a sub-range of the larger data set.
Below has the parts of my code relevant to where I am having trouble. I keep getting Run-time error 13 - type mismatch. See the first two lines in the For Each loop.
I have tried Appplication.Worksheetfunction.Match - same problem.
I have tried creating an array of just the first column - same problem.
If I specify the array element that has the matching contract number (i.e. ArrQData(2,1) the match will work, but obviously that does not acheive what I want. Can you not use Match with a VBA array?
Please help! The contract numbers are either numeric or Alpha-numeric.
Also, I have about 350,000 rows of data, but my understanding is that row limits no longer apply???? - only limit is memory?
In advance of anyone asking... I cannot upload my file - partly due to file size but also confidential data.
I have a VBA program for a large file, which works correctly but is slow.
I searching the internet I have see that working off an array vs. the worksheet drastically improves performace. I began converting my code to load my data into an array but am running into a problem with a couple code lines where I was using Function.Match to pull row numbers to create a sub-range of the larger data set.
Below has the parts of my code relevant to where I am having trouble. I keep getting Run-time error 13 - type mismatch. See the first two lines in the For Each loop.
I have tried Appplication.Worksheetfunction.Match - same problem.
I have tried creating an array of just the first column - same problem.
If I specify the array element that has the matching contract number (i.e. ArrQData(2,1) the match will work, but obviously that does not acheive what I want. Can you not use Match with a VBA array?
Please help! The contract numbers are either numeric or Alpha-numeric.
Also, I have about 350,000 rows of data, but my understanding is that row limits no longer apply???? - only limit is memory?
In advance of anyone asking... I cannot upload my file - partly due to file size but also confidential data.
Code:
Sub SearchContracts()
[INDENT]Dim wksContracts As Worksheet, wksQData As Worksheet
Dim ArrQData() As Variant
Dim QDataRows As Long, QDataCols As Long
Dim CntFrstRow As Long, CntLastRow As Long
Dim ContractList As Range, CntSrchRng As Range
Set wksContracts = ThisWorkbook.Sheets("Contract List")
Set wksQData = ThisWorkbook.Sheets("Query Results")
Set ContractList = wksContracts.Range("A1", wksContracts.Cells(Rows.Count, 1).End(xlUp))
QDataRows = wksQData.Cells(Rows.Count, 1).End(xlUp).Row
QDataRows = wksQData.Cells(1, Columns.Count).End(xlToLeft).Column
ArrQData = wksQData.Range("A1", wksQData.Cells(QDataRows, QDataCols))[/INDENT]
[INDENT]For Each Contract In CntList
[INDENT]CntFrstRow = Application.Match(Contract, Application.Index(ArrQData, 0, 1), 0)
CntLastRow = Application.Match(Contract, Application.Index(ArrQData, 0, 1), 1)
Set CntSrchRng = 'creates a subset of the array - range of "A & CntFrstRow" thru "N & CntLastRow"
Call FillBnftHist(CntSrchRng) 'manipulates the data in the range and outputs to a new file.[/INDENT]
Next Contract[/INDENT]
End Sub