For loop Each cell just for odd itteration?

GerrardSVK

New Member
Joined
Sep 18, 2023
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Is any possibility to make this order but with every 2 itterations only?

So for loop will go 1 step then 3 then 5 etc.



Code:
 For Each Cell In Workbooks(1).Sheets(2).Range(KopyRange).Cells
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You need to change the technique a little, but here is a simple demonstration that you can try on the active sheet to see how you can just process every second cell.

VBA Code:
Sub Test()
  Dim i As Long
  
  With Range("B1:B11")
    For i = 1 To .Rows.Count Step 2
      .Cells(i, 1).Interior.Color = vbGreen
    Next i
  End With
End Sub
 
Upvote 0
You need to change the technique a little, but here is a simple demonstration that you can try on the active sheet to see how you can just process every second cell.

VBA Code:
Sub Test()
  Dim i As Long
 
  With Range("B1:B11")
    For i = 1 To .Rows.Count Step 2
      .Cells(i, 1).Interior.Color = vbGreen
    Next i
  End With
End Sub
I do it on my own I just put simple if condition that make this step but thank you anyway.
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,654
Members
449,113
Latest member
Hochanz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top