Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
So with the help of this community I had put together a macro and COMPLETELY neglected the fact that is IS in the realm of possibility that for a supplier code there could be NO OPEN COMPLAINTS
So i ran into that situation to where it errored out because there was nothing to copy lol I believe my solution would be to put in "On Error Resume Next"? some where
or is there an alternative. I tried adding it right before ".Range("A2:AK...." and it was error free but it is there a way that if it errors i can just exit the With part all together?
So i ran into that situation to where it errored out because there was nothing to copy lol I believe my solution would be to put in "On Error Resume Next"? some where
or is there an alternative. I tried adding it right before ".Range("A2:AK...." and it was error free but it is there a way that if it errors i can just exit the With part all together?
VBA Code:
Sub Filter_MHP()
Worksheets("Complaints").Unprotect Password:="Secret"
Application.ScreenUpdating = False
Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet
Set srcWS = Sheets("Complaints")
Set desWS = Sheets("MH Portage")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
desWS.UsedRange.Offset(1).ClearContents
With srcWS
.Range("AW2:AW" & LastRow).Formula = "=IF(AND(D2=""0102-2"",M2>=TODAY()-7),""true"",IF(AND(D2=""0101-7"",ISBLANK(M2)),""true"",""false""))"
.Cells(1).CurrentRegion.AutoFilter 49, "true"
.Range("A2:AK" & LastRow).SpecialCells(xlCellTypeVisible).Copy
With desWS
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
.Columns.AutoFit
End With
.Range("A1").AutoFilter
.Columns("AW").Delete
End With
Application.ScreenUpdating = True
Worksheets("Complaints").Protect Password:="Secret"
ThisWorkbook.Save
End Sub