+ Reply to Thread
Results 1 to 5 of 5

For loop through specific Worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2015
    Location
    Portland
    MS-Off Ver
    2013
    Posts
    32

    For loop through specific Worksheets

    I need to create a for loop to cycle through Worksheets 2-6 to run an if statement on each individual one and take action on that specific sheet matches those conditions. This is what I have currently:

    Dim i As Long
    Dim j As Long
    If CheckBox1.Value = True Then
        For i = 3 To 373
            For j = 2 To 6
                If Sheet(j).Cells(8, i).Value = "CriteriaString1" Then
                    Sheet(j).Cells(8, i).EntireColumn.Hidden = False
                End If
            Next j
        Next i
    Else
        For i = 3 To 373
            For j = 2 To 6
                If Sheet(j).Cells(8, i).Value = "CriteriaString1" Then
                    Sheet(j).Cells(8, i).EntireColumn.Hidden = True
                End If
            Next j
        Next i
    End If

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: For loop through specific Worksheets

    That code looks fine, is there a problem with it?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-02-2015
    Location
    Portland
    MS-Off Ver
    2013
    Posts
    32

    Re: For loop through specific Worksheets

    When running it, I get the error "Compile error: Sub or Function not defined". Also, it highlights the word 'Sheet' in the if statement.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: For loop through specific Worksheets

    Oops, didn't spot that.

    Sheet should be Sheets.

  5. #5
    Registered User
    Join Date
    02-02-2015
    Location
    Portland
    MS-Off Ver
    2013
    Posts
    32

    Re: For loop through specific Worksheets

    Hahaha, wow.... Can't believe I missed that.... Thanks for the help, works just fine

+ 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. VBA loop to insert and delete worksheets in a specific sheet within a list
    By supppy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2014, 09:02 PM
  2. Loop for adding specific worksheets in specific workbooks
    By pankaj8219 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2013, 10:22 AM
  3. Call Macros before Next loop (loop creates new worksheets)
    By mantooth29 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2012, 05:47 PM
  4. How to loop through specific worksheets?
    By svenk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-11-2010, 12:15 PM
  5. [SOLVED] Loop through specific worksheets
    By Ben in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2005, 10:40 AM

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