Delete row not equal to value in A1 for each sheet

benntw

Board Regular
Joined
Feb 17, 2014
Messages
222
Office Version
  1. 365
Platform
  1. Windows
My worksheet creates copied sheets from a list. The list is from the values in column C. What I want to do is after it copies and renames the sheet, search column C for values that don't match A1. A1 is the a formula to equal the sheet name. My data in column C starts on the 3rd row. Below is my code to copy and rename each sheet. The number of sheets depends on how many cost objects I have in my list. I hope someone can help on this. Thank you.

Sub CreateSheetsFromCostObjects()

Dim ws As Worksheet, Ct As Long, c As Range

Set ws = Worksheets("EditReport")

Application.ScreenUpdating = False

For Each c In Sheets("SheetNames").Range("A2:A40")
If c.Value <> "" Then
ws.Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
Ct = Ct + 1
End If
Next c
If Ct > 0 Then
MsgBox Ct & " new sheets created from list"
Else
MsgBox "No names on list"
End If

Call CreateHyperlinks

Sheets("SheetNames").Select

Application.ScreenUpdating = True
End Sub
 
It took less than 1 minute to complete the entire code I had in there. I never even gave it a thought on how you ended up writing it.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,215,205
Messages
6,123,634
Members
449,109
Latest member
Sebas8956

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