For each construct excluding the last two sheets

  • Hi all,


    I am really stupid I cannot get a macro to exclude the last two sheets in a workbook when I am using a for each construct. I tired with the following and that did not fly:


    Anyone know how to exclude the two last sheets from the for each construct?


    /Robert

    .¸¸·´¯'·.¸¸.·´¯'·.¸¸·´¯'·.¸¸.·´¯'·.¸¸·´¯'·.¸¸.· ><((((º>

  • Re: For each construct excluding the last two sheets


    Hi Robert,


    Try a slightly different approach:


    HTH


    Edit : I'm out of practice - Dave is way too quick! ;)

  • Re: For each construct excluding the last two sheets


    Quote from Dave Hawley

    Hi Robert


    Try

    Code
    Sub Duh()
         
        Dim lLoop As Long
         
        For lLoop = 1 To Worksheets.Count - 2
            MsgBox Worksheets(lLoop).Name
        Next lLoop
    End Sub


    Hi Dave,
    This works really good thank you, the problem is that I am trying to run a countif formula in all the sheets except for the last two sheets.
    The code looks like this:


    Do you have any ideas to eliminate the last two sheets from this macro?


    //Robert :confused:

    .¸¸·´¯'·.¸¸.·´¯'·.¸¸·´¯'·.¸¸.·´¯'·.¸¸·´¯'·.¸¸.· ><((((º>

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!