Deleting column data when cell value that = page name not found

mystic_muffin

New Member
Joined
Apr 19, 2017
Messages
17
Hey, Friends;

I have this bit of code that I'm working with that looks through my worksheets and copies data from any worksheet that has a numeric name (job number). It fills a 'master' sheet.

I'm also run a script to delete these worksheets when the job is complete.

Right now to delete column data from my 'master', I'm comparing the values in row 1 vs a hidden table of contents and doing a countif, then deleting anything with a 0 in the master row 2... which is obviously very inefficient.

Is there an easier way to delete the column data if the cell data in row 1 no longer corresponds with a worksheet title?


Here is what I'm using to populate that master sheet:

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


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

I appreciate any help and explanation as I'm still learning how to refine my skills.

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top