ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping worksheets in workbook (https://www.excelbanter.com/excel-programming/325718-looping-worksheets-workbook.html)

Wylie C

Looping worksheets in workbook
 
I need help with a macro that will loop through all worksheets in a workbook
and delete the worksheet if the contents in A15 < "C" then re-loop and
delete the "C" in each workbook. Should I create a named range using A15 in
each workbook or just the cell reference as above?

Thank you.

Bob Phillips[_6_]

Looping worksheets in workbook
 

Application.DisplayAlerts = False
For Each sh In Activeworkbook.Worksheets
If sh.Range("A15").Value < "C" Then
sh.Delete
Else
sh.Range("A15").Value = "C"
End If
Next sh

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wylie C" wrote in message
...
I need help with a macro that will loop through all worksheets in a

workbook
and delete the worksheet if the contents in A15 < "C" then re-loop and
delete the "C" in each workbook. Should I create a named range using A15

in
each workbook or just the cell reference as above?

Thank you.




Tushar Mehta

Looping worksheets in workbook
 
The code below is untested. Like Bob's it uses a single pass through
the workbook but differs on what it does with non-deleted worksheets.

Option Explicit

Sub testIt()
Dim aWS As Worksheet
For Each aWS In ActiveWorkbook.Worksheets
With aWS.Range("A15")
If .Value < "C" Then
.Parent.Delete
Else
.ClearContents
End If
Next aWS
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
I need help with a macro that will loop through all worksheets in a workbook
and delete the worksheet if the contents in A15 < "C" then re-loop and
delete the "C" in each workbook. Should I create a named range using A15 in
each workbook or just the cell reference as above?

Thank you.



All times are GMT +1. The time now is 01:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com