# Thread: Skipping Specific Row Within a Loop Thanks:  2 Post #5324020 (1)Post #5323986 (1) Likes:  4 Post #5324020 (2)Post #5324665 (1)Post #5323986 (1)

1. ## Skipping Specific Row Within a Loop

Good day all,

I have a quick question: I am running a loop which copies certain cells from rows according to an IF statement from a different worksheet.

My code runs from i = 9 to i = 61 but I need it to ignore row 21, as it meets the IF condition yet I still want it to be ignored, how would I go about doing so?

Thanks in advance Code:
```Sub CopyTasks ()

Application.ScreenUpdating = False

Dim i As Long
Dim r As Long
r = 12

For i = 9 To 61
With Sheets("TimeSheet")
If .Cells(i, "K").Value >= 0.1 And .Cells(i, "K").Value <= 24 Then
.Cells(i, "B").Resize(, 2).Copy: Sheets("Monday").Cells(r, "C").PasteSpecial xlValues
.Cells(i, "E").Copy: Sheets("Monday").Cells(r, "E").PasteSpecial xlValues
.Cells(i, "G").Copy: Sheets("Monday").Cells(r, "I").PasteSpecial xlValues
r = r + 5
End If
End With

Next
Application.ScreenUpdating = True
End Sub```  Reply With Quote

2. ## Re: Skipping Specific Row Within a Loop

One way:
Code:
```Application.ScreenUpdating = False

Dim i As Long
Dim r As Long
r = 12

For i = 9 To 61
If i <>21 Then
With Sheets("TimeSheet")
If .Cells(i, "K").Value >= 0.1 And .Cells(i, "K").Value <= 24 Then
.Cells(i, "B").Resize(, 2).Copy: Sheets("Monday").Cells(r, "C").PasteSpecial xlValues
.Cells(i, "E").Copy: Sheets("Monday").Cells(r, "E").PasteSpecial xlValues
.Cells(i, "G").Copy: Sheets("Monday").Cells(r, "I").PasteSpecial xlValues
r = r + 5
End If
End With
End If
Next
Application.ScreenUpdating = True
End Sub```  Reply With Quote

3. ## Re: Skipping Specific Row Within a Loop

Hey Joe4,

Yeah, that's exactly what I needed, now I can get on with the rest of the code. I hadn't excluded rows before so I was unsure how to approach it.

Thanks a bunch and have a nice day! Originally Posted by Joe4 One way:
Code:
```Application.ScreenUpdating = False

Dim i As Long
Dim r As Long
r = 12

For i = 9 To 61
If i <>21 Then
With Sheets("TimeSheet")
If .Cells(i, "K").Value >= 0.1 And .Cells(i, "K").Value <= 24 Then
.Cells(i, "B").Resize(, 2).Copy: Sheets("Monday").Cells(r, "C").PasteSpecial xlValues
.Cells(i, "E").Copy: Sheets("Monday").Cells(r, "E").PasteSpecial xlValues
.Cells(i, "G").Copy: Sheets("Monday").Cells(r, "I").PasteSpecial xlValues
r = r + 5
End If
End With
End If
Next
Application.ScreenUpdating = True
End Sub```  Reply With Quote

4. ## Re: Skipping Specific Row Within a Loop

You are welcome.
Glad I was able to help!   Reply With Quote

5. ## Re: Skipping Specific Row Within a Loop

Another way, particularly useful if there are several values to exclude:
Code:
```For i = 9 To 61
Select Case i
Case 10, 14 To 17, 21
'Do nothing for the above values/ranges
Case Else
With Sheets("TimeSheet")
If .Cells(i, "K").Value >= 0.1 And .Cells(i, "K").Value <= 24 Then
.Cells(i, "B").Resize(, 2).Copy: Sheets("Monday").Cells(r, "C").PasteSpecial xlValues
.Cells(i, "E").Copy: Sheets("Monday").Cells(r, "E").PasteSpecial xlValues
.Cells(i, "G").Copy: Sheets("Monday").Cells(r, "I").PasteSpecial xlValues
r = r + 5
End If
End With
End Select
Next```  Reply With Quote

6. ## Re: Skipping Specific Row Within a Loop

I ended up using this method for another document, I am quite familiar with the Case statement but I never thought about using it this way!

Thanks a bunch to both of you  Originally Posted by Peter_SSs Another way, particularly useful if there are several values to exclude:
Code:
```For i = 9 To 61
Select Case i
Case 10, 14 To 17, 21
'Do nothing for the above values/ranges
Case Else
With Sheets("TimeSheet")
If .Cells(i, "K").Value >= 0.1 And .Cells(i, "K").Value <= 24 Then
.Cells(i, "B").Resize(, 2).Copy: Sheets("Monday").Cells(r, "C").PasteSpecial xlValues
.Cells(i, "E").Copy: Sheets("Monday").Cells(r, "E").PasteSpecial xlValues
.Cells(i, "G").Copy: Sheets("Monday").Cells(r, "I").PasteSpecial xlValues
r = r + 5
End If
End With
End Select
Next```  Reply With Quote

7. ## Re: Skipping Specific Row Within a Loop Originally Posted by Chirolove Thanks a bunch to both of you You are very welcome. Thanks for the follow-up.   Reply With Quote

## User Tag List

#### Tags for this Thread

exclude, k.value, loop, row, skip #### Posting Permissions

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