Kemidan2014
Board Regular
- Joined
- Apr 4, 2022
- Messages
- 229
- Office Version
- 365
- Platform
- Windows
I have a piece of code that worked perfectly until recently and now it is throwing up an error. Here is the odd bit, i can F8 step through it and it goes through just fine but when i use the assigned macro button it gives me this error 50% of the time.
The only other addition to the work book as a whole is a new worksheet that does not use the sheet i am trying to macro. Is this purely a "too much going on" issue?
Hitting Debug Highlights this line
The only thing that i added to this macro was unprotecting and protecting Worksheets("AACT")
The only other addition to the work book as a whole is a new worksheet that does not use the sheet i am trying to macro. Is this purely a "too much going on" issue?
Hitting Debug Highlights this line
The only thing that i added to this macro was unprotecting and protecting Worksheets("AACT")
VBA Code:
Sub Filter_Data()
Worksheets("Complaints").Unprotect Password:="Secret"
Worksheets("AACT").Unprotect Password:="Secret"
Application.ScreenUpdating = False
Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet
Set srcWS = Sheets("Complaints")
Set desWS = Sheets("AACT")
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastrowb = desWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
desWS.Range(Cells(2, 1), Cells(50, 49)).ClearContents
With srcWS
.Range("AV2:AV" & LastRow).Formula = "=IF(AND(D2=""0101-6"",M2>=TODAY()-7),""true"",IF(AND(D2=""0101-6"",ISBLANK(M2)),""true"",""false""))"
.Cells(1).CurrentRegion.AutoFilter 48, "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("AV").ClearContents
End With
With desWS
.Range(Cells(2, 27), Cells(50, 28)).ClearContents
.Range("AA2:AA" & lastrowb).Formula = "=IF(ISBLANK(J2),"" "",IF(ISBLANK(P2),Today()-J2,P2-J2))"
.Range("AB2:AB" & lastrowb).Formula = "=IF(ISBLANK(K2),"" "",IF(ISBLANK(S2),Today()-K2,S2-K2))"
End With
Application.ScreenUpdating = True
Worksheets("Complaints").Protect Password:="Secret"
Worksheets("AACT").Protect Password:="Secret"
ThisWorkbook.Save
End Sub