mightymorgs
New Member
- Joined
- Dec 22, 2021
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
I'm using a code that was working perfectly. A few weeks went by before I had to use it again and now I'm getting the subject error. The error flags when it gets to line 12 at the "ws.Control.ListObjects..." It seems that the code isn't finding the worksheet named "Control," even though that worksheet is clearly labeled within my workbook. Any suggestions on how to correct it?
VBA Code:
Sub Delete()
Dim ws As Worksheet
Dim lastrow As Long
Dim i As Long
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
For Each ws In ThisWorkbook.Worksheets
If TryMatch(Lookup:=ws.Name, _
Lookin:=wsControl.ListObjects("tblTarget").DataBodyRange) Then
ws.Range("A:A,B:B,C:C,D:D,E:E,M:M,N:N,Q:Q,R:R").Delete
End If
If TryMatch(Lookup:=ws.Name, _
Lookin:=wsControl.ListObjects("tblTarget").DataBodyRange) Then
lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For i = lastrow To 1 Step -1
If TryMatch(Lookup:=ws.Cells(i, "A").Interior.Color, _
Lookin:=wsControl.ListObjects("tblColours").ListColumns(2).DataBodyRange) Then
ws.Rows(i).Delete
End If
Next i
End If
If TryMatch(Lookup:=ws.Name, _
Lookin:=wsControl.ListObjects("tblTarget").DataBodyRange) Then
ws.Select
ws.Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If
If TryMatch(Lookup:=ws.Name, _
Lookin:=wsControl.ListObjects("tblTarget").DataBodyRange) Then
ws.Range("A1:J1").Value = Array("EE #", "mfg", "Serial #", "Initial Status", "Final Status", "Cost", "Description", "CSN", "CSN Description", "Category")
End If
Next ws
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub