PDA

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



kilbey1
09-26-2008, 01:23 PM
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?



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

xld
09-26-2008, 02:50 PM
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

kilbey1
09-26-2008, 02:59 PM
Thanks, xld. Just what I needed.