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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

teatimecrumpet

Active Member
Joined
Jun 23, 2010
Messages
307
Hi could a moderator please delete this thread? It is a duplicate created by pressing the back button on the browser.

Thanks
 

Forum statistics

Threads
1,141,017
Messages
5,703,752
Members
421,313
Latest member
Mooncake1

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
Top