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.
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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
 

mjpst6

New Member
Joined
Jan 28, 2005
Messages
15
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.
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
OK, that's what my code does and it tested fine, so post back if you run into problems.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,601
Messages
5,597,117
Members
414,126
Latest member
jellevansoelen

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
Top