Repeat Do Loop, nested in If statement

cmeier7

Board Regular
Joined
Jul 23, 2009
Messages
64
Hello, I am trying to repeat a Do Loop given a specific property return in an If Statement. For example, for the first part of it I have:

Code:
Do
        
r = ActiveCell.Row
If r < 53 Then
    a = "C"
    b = r - 1
    If Sheets(n).Cells(b, 3).Interior.ColorIndex = 15 Then
        ActiveCell.Offset(1, 0).Select
        Loop
    Else
    End If
ActiveCell.Value = "='" & n & "'!" & a & "" & b & ""
Loop


The Loop in the middle I want to automatically return back to the top of the Do Loop (without completeing the ActiveCell.Value. Basically I want everything after that Loop to not happen, and instead automatically repeat the Do Loop. Is this possible?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You have to use a GOTO to do this. Typically, GOTO is considered pretty evil and should be avoided. It might be hard to understand why in simple cases, but when you start reading code that has hundreds and hundreds you'll get the idea.

Code:
Do
 
r = ActiveCell.Row
If r < 53 Then
    a = "C"
    b = r - 1
    If Sheets(n).Cells(b, 3).Interior.ColorIndex = 15 Then
        ActiveCell.Offset(1, 0).Select
        GOTO Continue01
    Else
    End If
ActiveCell.Value = "='" & n & "'!" & a & "" & b & ""
 
Continue01:
Loop

here is a link that may be helpful to you if you choose to re-write in a more structured way.
http://www.mrexcel.com/forum/showthread.php?t=260786
skim down to pgc01's remarks.
 
Last edited:
Upvote 0
Thanks, yes I can only imagine how confusing and messy using GoTos could get if you used them all the time. I will only be using it for this one situation. Thank you again.
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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