Delete cells if job sheet no longer exists

Viewed 63

Everyone;

I have this bit of code that copies data from worksheets with a numeric name (a job number) and pasts them into a column +1 on a master sheet to be email off every night.

I want to delete job pages when the jobs are complete. When I delete a page, my data isn't being removed from the Master Email sheet.

How can I modify this code to delete from cells 18-39 in column XXX if the value in cell 19 (the job number) is no longer in the workbook?

Thanks for any help!

Private Sub Worksheet_Activate()
    Dim ws, MASTER111 As Worksheet
    Dim ColIndex As Integer
    Dim CopyRange As Range
    Set Master = ThisWorkbook.Sheets("MASTER111")

    ColIndex = 2 'first column on Master sheet to paste data
    For Each ws In ThisWorkbook.Worksheets
        If IsNumeric(ws.Name) Then
           Master.Cells(19, ColIndex) = ws.Range("A1") 'put job name in first row
           Set CopyRange = Intersect(ws.UsedRange, ws.Range("N:N"))
           CopyRange.Copy
           Master.Cells(16, ColIndex).PasteSpecial xlValues
           Master.Cells(18, ColIndex) = "Job #"
           Master.Cells(19, ColIndex) = ws.Range("A1") 'put job name in first row
           ColIndex = ColIndex + 1
           Set CopyRange = Nothing
        End If
    Next ws
End Sub
1 Answers
Related