Loop with loops

teatimecrumpet

Active Member
Joined
Jun 23, 2010
Messages
307
Hi I'm trying to run the below code that would go through each worksheet and run some code But it's only running the code for the initial activated worksheet.

Any thoughts?

Sub totaldelete()
For Each Worksheet In ActiveWorkbook.Worksheets

Cells.Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Deletes rows above cell that contains the text Yellow
Dim foundOne As Range
On Error Resume Next
With ActiveWorkbook.ActiveSheet
Set foundOne = .Range("A:A").Find(What:="Yellow", After:=.Range("a1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If foundOne.Row > 1 Then
Range(.Range("a1"), foundOne.Offset(-1, 0)).EntireRow.Delete shift:=xlUp
End If
End With
On Error GoTo 0

'gets rid of merged cells
Cells.Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

'searches each row for the word "total" and deletes that row
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If LCase(Cells(i, 1).Value) = "total" Then _
Cells(i, "A").EntireRow.Delete
Next

Next Worksheet

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi could a moderator please delete this thread? It is a duplicate created by pressing the back button on the browser.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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