+ Reply to Thread
Results 1 to 3 of 3

loop through worksheets but ignore certain worksheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    loop through worksheets but ignore certain worksheets

    Hello. This code loops through my worksheets but I want it to ignore the sheet called Master. How can I do this?

    Sub men()
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    ' Begin the loop.
    For I = 1 To WS_Count
    
           Worksheets(I).Activate
           Range("B3:B8").Select
           Selection.Copy
           Range("B29:B35").Select
           Selection.PasteSpecial Paste:=xlPasteValues
           Range("B38:B43").Select
           Selection.PasteSpecial Paste:=xlPasteValues
           Range("B35") = "Sum of Monthly Claims"
           Range("B35:O35").Font.Bold = True
           Range("B44") = "Total Claims"
           Range("B44").Font.Bold = True
           
           Range("C29:O34").Formula = "=C12*C3"
           Range("C35:O35").Formula = "=SUM(C29:C34)"
           Range("C38:C43").Formula = "=C20*C3"
           Range("C44").Formula = "=SUM(C38:C43)"
    Next I
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: loop through worksheets but ignore certain worksheets

    Use IF statement to validate the worksheet name

    Sub men()
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    ' Begin the loop.
    For I = 1 To WS_Count
        If Worksheets(I).Name <> "Master" Then
           Worksheets(I).Activate
           Range("B3:B8").Select
           Selection.Copy
           Range("B29:B35").Select
           Selection.PasteSpecial Paste:=xlPasteValues
           Range("B38:B43").Select
           Selection.PasteSpecial Paste:=xlPasteValues
           Range("B35") = "Sum of Monthly Claims"
           Range("B35:O35").Font.Bold = True
           Range("B44") = "Total Claims"
           Range("B44").Font.Bold = True
           
           Range("C29:O34").Formula = "=C12*C3"
           Range("C35:O35").Formula = "=SUM(C29:C34)"
           Range("C38:C43").Formula = "=C20*C3"
           Range("C44").Formula = "=SUM(C38:C43)"
        End If
    Next I
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: loop through worksheets but ignore certain worksheets

    That's that good isht. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compare two worksheets but ignore cells which have formulas
    By vwyeth in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2013, 04:16 PM
  2. VBA ignore or skip worksheets if not available
    By sk88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 04:15 PM
  3. [SOLVED] VBA Code To Ignore Missing Worksheets within a Workbook
    By Dave.b in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-23-2013, 11:47 AM
  4. Do while loop to delete worksheets if worksheets are not in the specified list
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2011, 03:02 PM
  5. Macro to ignore certain worksheets
    By erikab121 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2010, 02:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1