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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,216,025
Messages
6,128,352
Members
449,443
Latest member
Chrissy_M

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