Loop through column C then column E then column G

mjpst6

New Member
Joined
Jan 28, 2005
Messages
15
Any way I can make this code do a loop for column C and then E and then G?

Application.GoTo Range("G2"), True

' This loop repeats for a fixed number of times determined by the number of rows

' in the range

Dim i As Integer

r = 2


For i = 1 To Selection.CurrentRegion.Rows.Count - 1


Call New_Sheet(r) ' Run New_Sheet Code


ActiveCell.Offset(1, 0).Select

r = r + 1

Next i


With the code above I'd have to change the starting point three times and run the macro manually three times. I'd like the user to only have to run it 1 time.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Guessing here, because your code is a bit cryptic (you did not declare the "r" variable) and you are doing a lot of selecting and activating, probably unnecessarily, but try this approach:


Dim i As Integer, j As Integer, r
j = 3
Do
Application.Goto Cells(2, j), True
r = 2
For i = 1 To Selection.CurrentRegion.Rows.Count - 1
Call New_Sheet(r)
ActiveCell.Offset(1, 0).Select
r = r + 1
Next i
MsgBox ActiveCell.Address
j = j + 2
Loop While j <= 7
 
Upvote 0
Thanks Tom. You're right I didn't include all of the code. The key though is I just want a loop that will cycle through all of the data in column C and then through all of the data in column E and then through all of the data in column G and then that's when it will stop.
 
Upvote 0
OK, that's what my code does and it tested fine, so post back if you run into problems.
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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