![]() |
Add Second Page to Code
Good Afternoon All,
I have a macro that excludes a certain page from the Clear code I'm using below. I now have a second page named "Front Page 2" that I am also looking to exclude from this function. After several feeble attempts to modify and add "Front Page 2" to this code, I've been unsuccessful and was wondering if someone had an idea that would enable this request. Thanks so much in advance - Jenny B. Sub Clear() For Each Ws In Worksheets If Ws.Name < "Front Page" Then Application.ScreenUpdating = False Ws.Activate Dim RangeClear As Range Set RangeClear = Range("a:IV") RangeClear.ClearContents Range("A1").Select ActiveCell.FormulaR1C1 = "0" Sheets("Front Page").Select End If Next Application.ScreenUpdating = True End Sub |
Add Second Page to Code
Option Explicit
Sub Clear() 'Dim RangeClear As Range 'don't need this anymore Dim ws As Worksheet For Each ws In Worksheets Select Case LCase(ws.Name) Case Is = lcase("front page"), lcase("front page 2") 'skip it Case Else ws.Cells.ClearContents ws.Range("A1").Value = 0 'or "0"? End Select Next ws End Sub You may decide to avoid all the "front page #" worksheets: Option Explicit Sub Clear() Dim ws As Worksheet For Each ws In Worksheets If LCase(Left(ws.Name, 10)) = LCase("front page") Then 'skip it Else ws.Cells.ClearContents ws.Range("A1").Value = 0 'or "0"? End If Next ws End Sub Jenny B. wrote: Good Afternoon All, I have a macro that excludes a certain page from the Clear code I'm using below. I now have a second page named "Front Page 2" that I am also looking to exclude from this function. After several feeble attempts to modify and add "Front Page 2" to this code, I've been unsuccessful and was wondering if someone had an idea that would enable this request. Thanks so much in advance - Jenny B. Sub Clear() For Each Ws In Worksheets If Ws.Name < "Front Page" Then Application.ScreenUpdating = False Ws.Activate Dim RangeClear As Range Set RangeClear = Range("a:IV") RangeClear.ClearContents Range("A1").Select ActiveCell.FormulaR1C1 = "0" Sheets("Front Page").Select End If Next Application.ScreenUpdating = True End Sub -- Dave Peterson |
Add Second Page to Code
Good Morning,
Thank you Dave. Both are teffific solutions to accomplish the same objective. Thanks once again for your prompt response and great advice - Jenny B. "Dave Peterson" wrote: Option Explicit Sub Clear() 'Dim RangeClear As Range 'don't need this anymore Dim ws As Worksheet For Each ws In Worksheets Select Case LCase(ws.Name) Case Is = lcase("front page"), lcase("front page 2") 'skip it Case Else ws.Cells.ClearContents ws.Range("A1").Value = 0 'or "0"? End Select Next ws End Sub You may decide to avoid all the "front page #" worksheets: Option Explicit Sub Clear() Dim ws As Worksheet For Each ws In Worksheets If LCase(Left(ws.Name, 10)) = LCase("front page") Then 'skip it Else ws.Cells.ClearContents ws.Range("A1").Value = 0 'or "0"? End If Next ws End Sub Jenny B. wrote: Good Afternoon All, I have a macro that excludes a certain page from the Clear code I'm using below. I now have a second page named "Front Page 2" that I am also looking to exclude from this function. After several feeble attempts to modify and add "Front Page 2" to this code, I've been unsuccessful and was wondering if someone had an idea that would enable this request. Thanks so much in advance - Jenny B. Sub Clear() For Each Ws In Worksheets If Ws.Name < "Front Page" Then Application.ScreenUpdating = False Ws.Activate Dim RangeClear As Range Set RangeClear = Range("a:IV") RangeClear.ClearContents Range("A1").Select ActiveCell.FormulaR1C1 = "0" Sheets("Front Page").Select End If Next Application.ScreenUpdating = True End Sub -- Dave Peterson |
All times are GMT +1. The time now is 01:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com