Consulting

Results 1 to 3 of 3

Thread: Solved: Why is vba not obeying an if statement to skip a sheet?

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    20
    Location

    Solved: Why is vba not obeying an if statement to skip a sheet?

    In this code, I am copying issues that are highlighted yellow into a sheet. I want to skip a sheet with a specific name ("Release 3.0"), but it doesn't seem to be obeying my if statement. Am I missing something?


    [vba]
    Sub copyNewIssues()

    Dim SheetWiseMax() As Double
    Dim i As Long
    Dim maxRow As Integer
    Dim myWorksheet As Worksheet

    Set myWorksheet = Worksheets(1) 'use the name/index of your worksheet
    Range("A2:L4000").Delete
    Range("A2").Select

    With ThisWorkbook
    ReDim SheetWiseMax(1 To .Sheets.Count)
    For i = 1 To .Sheets.Count
    If Sheets("Release 3.0").Name Then
    ActiveSheet.Next.Select
    Else
    For Each cell In Sheets(i).Range("A:A")
    If cell.Interior.ColorIndex = 6 Then
    cell.Resize(, 12).Copy Sheets("New Issues").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
    Next cell
    End If
    Next i
    End With
    End Sub
    [/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub copyNewIssues()

    Dim SheetWiseMax() As Double
    Dim i As Long
    Dim maxRow As Integer
    Dim myWorksheet As Worksheet

    Set myWorksheet = Worksheets(1) 'use the name/index of your worksheet
    Range("A2:L4000").Delete
    Range("A2").Select

    With ThisWorkbook
    ReDim SheetWiseMax(1 To .Sheets.Count)
    For i = 1 To .Sheets.Count
    If Not Sheets(i).Name = "Release 3.0" Then
    For Each cell In Sheets(i).Range("A:A")
    If cell.Interior.ColorIndex = 6 Then
    cell.Resize(, 12).Copy Sheets("New Issues").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
    Next cell
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    20
    Location
    Thanks, xld. Just what I needed.

Posting Permissions

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