logandiana
Board Regular
- Joined
- Feb 21, 2017
- Messages
- 107
I have a procedure that uses the advanced filter.
BOD is data on a sheet in another open workbook
crit and Plnt are different sheets in the macro workbook
This code DOES work. It runs fast and without issue about 90% of the time.
The other 10% of the time it crashes Excel, no spinning, no error messages, no warning. All Excel just disappears.
This is the same whether running the code or stepping through in debug.
The the criteria never changes. The only data that sometimes changes is the data that's on BOD.
But I have tested it repeatedly with the same data and I always hold my breath when I hit the button.
I can't figure out what causes it though. Is there a different way to write it so that it works 100% of the time?
Is it a computer issue? I have 16gb of RAM and an 8 core i7.
I have other things declared at the top of the module.
Am I declaring too much?
BOD is data on a sheet in another open workbook
crit and Plnt are different sheets in the macro workbook
VBA Code:
Dim rgData, rgCriteria, rgOutput As Range
Set rgData = BOD.Range("A1").CurrentRegion
Set rgCriteria = crit.Range("A1").CurrentRegion
Set rgOutput = Plnt.Range("B" & LR1 + 2).CurrentRegion
rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput '<<<< this line seems to be the issue
This code DOES work. It runs fast and without issue about 90% of the time.
The other 10% of the time it crashes Excel, no spinning, no error messages, no warning. All Excel just disappears.
This is the same whether running the code or stepping through in debug.
The the criteria never changes. The only data that sometimes changes is the data that's on BOD.
But I have tested it repeatedly with the same data and I always hold my breath when I hit the button.
I can't figure out what causes it though. Is there a different way to write it so that it works 100% of the time?
Is it a computer issue? I have 16gb of RAM and an 8 core i7.
I have other things declared at the top of the module.
Code:
Dim OWI, BO, TempWB, book As Workbook
Dim Iss, Plnt, VC, CCA, crit, BOD, emls As Worksheet
Dim LR1, LR2, LReml, lastrow, lastrow2, lastrow3, lastrow4 As Long
Dim olApp As Outlook.Application
Dim olFolder As Outlook.MAPIFolder
Dim olNewmail, olNewmail2 As Outlook.MailItem
Dim rgData, rgCriteria, rgOutput, emailRng, cl As Range
Dim who, BOname, sTo, currentsig, signatfile, TempFile1, TempFile2, TempFile3, Tempfile4 As String
Dim htmlrng As Range
Dim htmlrng2 As Range
Dim htmlrng3 As Range
Dim htmlrng4 As Range
Dim ts As Object
Dim fso As Object
Am I declaring too much?