Hello all, I have a vba code that filters a table based on a list and some items in the list will not show up in the filtered table. How do I go about skipping that item and go to the next item. I know there is a combination of If and Then but don't know the right construct.
The workbook is a lengthy macro workbook that has varied moving parts. I am only pasting the code associated with this issue.
So from the above code. If the MyCell filtered data table is blank, I want it to skip and then move on to the next one. I think the error lies in the code below
but I do not know how to fix.
let me know if you need the entire source file
The workbook is a lengthy macro workbook that has varied moving parts. I am only pasting the code associated with this issue.
Code:
'----------------------- CODE TO COPY TO DRG TAB
Sheets("DRG").Activate
Set DestCellDRG = TargetShDRG.Range("DRG_START_CELL")
Set DestCellDRG = DestCellDRG.Offset(1, 0)
TargetShDRG.Activate
Rows("2:" & Rows.Count).ClearContents
For Each MyCell In MyRange
LastRow = ActiveSheet.Range("A700").End(xlUp).Row
If MyCell.Value = "" Then Exit For ' this exits when you have a blank cell
wkbkGen.Activate
Worksheets("DRG discharges").Activate
'select the range and autofilter based on hospital name
Range("a6").Select
With ActiveSheet
.AutoFilterMode = False
.Range("DISCH_DRG_TBL").AutoFilter
.Range("DISCH_DRG_TBL").AutoFilter field:=2, Criteria1:=MyCell
.Range("DISCH_DRG_TBL").AutoFilter field:=11, Criteria1:=Array( _
"1", "2", "3", "4", "5"), Operator:=xlFilterValues
End With
If(tbl.Rows.Count <1)Then
Next MyCell
ActiveCell.CurrentRegion.Select
Set tbl = ActiveCell.CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Select
Selection.Copy
'activate template
wkbkTemp.Activate
TargetShDRG.Activate
TargetShDRG.Range(DestCellDRG.Address).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCellDRG = TargetShDRG.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
Else
Next MyCell
So from the above code. If the MyCell filtered data table is blank, I want it to skip and then move on to the next one. I think the error lies in the code below
Code:
If(tbl.Rows.Count <1)Then
Next MyCell
but I do not know how to fix.
let me know if you need the entire source file