Chirag R Raval
Member
Dear all respected Sirs & Experts ,
Simple macro I run.
1st loop, open one by one each file of predefined folder,
2nd inner loop for Advance filter on database for multiple criteria rows on that opened file, & copy result to destination file & close that file,
If there are no rows left for filter, naturally , control re-pass to 1st loop, for open next file for same process.
I also put check in inner loop (Adv Filter), that if no match found for criteria row, so filtered row blanks , if after header row, checks count visible cells , if there are no visible cells except first row, its jump on label skip:
I run below code, though all main procedure complete of advance filter on every opened files & copy filtered result to next sheet , when start new process on destination sheet, macro stop on some weird place , its display below error

I search for solution for it but I can not figure out what mistake I do in my code.
Microsoft says below.

Though , Microsoft suggest not to jump out from loop, i need to jump on label skip: so I already put iferror goto skip laben in inner loop, but error not raised on inner loop, its raised on main file opening loop, 1st loop, or parent loop of inner loop.
Though all process of file opening & filtration process complete, weirdly its raised on next procedure of simple formatting.
After all process complete, & already start formatting, that not part of that both loop, like its suddenly realise something forgot to do in outer main loop & re-jump in file opening loop's "Next r" line ,stop, & raise that error.
Hope some solution there because I already stuck that error since last 5 days, can not outcome..
Please help , will be appreciated.
Regards,
Chirag Raval
Simple macro I run.
1st loop, open one by one each file of predefined folder,
2nd inner loop for Advance filter on database for multiple criteria rows on that opened file, & copy result to destination file & close that file,
If there are no rows left for filter, naturally , control re-pass to 1st loop, for open next file for same process.
I also put check in inner loop (Adv Filter), that if no match found for criteria row, so filtered row blanks , if after header row, checks count visible cells , if there are no visible cells except first row, its jump on label skip:
I run below code, though all main procedure complete of advance filter on every opened files & copy filtered result to next sheet , when start new process on destination sheet, macro stop on some weird place , its display below error

Code:
'ADVANCE FILTER ON MULTIPLE CRITERA , multi critera , multi_critera & SEPRATE THAT FILE BASIC CODE
'https://chandoo.org/forum/threads/formula-for-advance-filter-on-multiple-criteria-for-separate-each-filtered-instance-as-new-file.36314/#post-218502
'ASKED FROM CHIRAG
'ANSWERED BY MR NARAYANK991
'Sub STG_MasterOrdStaMultCriSepFile()
Sub advfilterandcopytonxtsht()
Dim lrow As Long
Dim i As Integer
Dim criteriarows As Long
Dim inputdatarange As Range
Dim criteria_range As Range
Dim rw As Variant
Dim criteria_header As Range
Dim crange As Range
Dim Criteria As New Collection
With swsht
If .AutoFilterMode Then .Cells.AutoFilter
lrow = .Cells(Rows.Count, 1).End(xlUp).Row
Set inputdatarange = .Range("A1:I" & lrow)
criteriarows = .Range("K" & Rows.Count).End(xlUp).Row
Set criteria_range = .Range("K2:K" & criteriarows).Resize(, 6)
Set crange = .Range("R1:R2").Resize(, 6)
End With
On Error GoTo SKIP
For Each rw In criteria_range.Rows
crange.Cells(2, 1).Resize(, 6) = rw.Value
inputdatarange.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=crange, Unique:=False
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'most imp
'http://www.vbaexpress.com/forum/archive/index.php/t-18419.html
'herzberg 03-16-2008, 11:28 PM
'I work with Autofilters a lot too. Here's what I use:
Dim counter As Integer
With inputdatarange
counter = .Columns(1).SpecialCells(xlCellTypeVisible).Count
If counter = 1 Then
If ActiveSheet.FilterMode Then ActiveSheet.showAllData
GoTo SKIP
'Occurs when no records are returned. Exit Sub here or something
'Basically, I count the number of visible rows. When it's 1, it means only the header is there and no records are returned.
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ElseIf destsht.Range("A1") = "" Then
swsht.Range("A1:I" & lrow).Copy
Else
swsht.Range("A2:I" & lrow).Copy
End If
End With
destsht.Activate
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If destsht.Range("A1") = "" Then
destsht.Range("A1").Activate
Else
'REMEMBER IF NO DATA FOUND THEN ("A").END METHOD FAIL &
'ROWS 1 WILL BE OVER WRITTEN THEN SECURED & MUST BE USED ROWS COUNT METHOD AS BELOW
destsht.Range("A" & Rows.Count).End(xlUp).Offset(1).Activate
End If
ActiveCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
mainsht.Activate
' Next
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SKIP:
Next rw
SWBK.Activate
If ActiveSheet.FilterMode Then ActiveSheet.showAllData
ActiveSheet.AutoFilterMode = False
SWBK.Close SaveChanges:=False
DoEvents
destwbk.Sheets(1).Activate
Next r
'FILTER COPY FINISH
'NOW OTHER PROCESS OF FORMATTING AND BUYER NAME ADDED PROCESS START BELOW
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
destwbk.Sheets(2).Activate
ActiveSheet.Range("c:c").NumberFormat = ("dd/mm/yyyy")
Columns.AutoFit
Set destwbk = Nothing
Set SWBK = Nothing
Application.Run "personal.xlsb!STGCompIndexMatchclosedPhoneOK"
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'warning from here last row can not access with variable lrow so construct new AS DIRECT TILL COLUMN A'S END NOT END.UP
Dim LastRow As Long
' Find Last Row
LastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
' Select Range
ActiveSheet.Range("A1:T" & LastRow).Select
With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
With ActiveSheet.Range("A1:T" & LastRow)
.Font.Size = 9
.Font.name = "Calibri"
End With
With ActiveSheet.Range("A1:T" & LastRow)
.LineStyle = xlContinuous
.Weight = xlThin
End With
End Sub
I search for solution for it but I can not figure out what mistake I do in my code.
Microsoft says below.

Though , Microsoft suggest not to jump out from loop, i need to jump on label skip: so I already put iferror goto skip laben in inner loop, but error not raised on inner loop, its raised on main file opening loop, 1st loop, or parent loop of inner loop.
Though all process of file opening & filtration process complete, weirdly its raised on next procedure of simple formatting.
After all process complete, & already start formatting, that not part of that both loop, like its suddenly realise something forgot to do in outer main loop & re-jump in file opening loop's "Next r" line ,stop, & raise that error.
Hope some solution there because I already stuck that error since last 5 days, can not outcome..
Please help , will be appreciated.
Regards,
Chirag Raval
Last edited: