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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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