Nested Do Loops

Ed Song

Board Regular
Joined
Sep 1, 2014
Messages
90
I have a double nested Do loop consisting of an outer and inner do loop. I'm having trouble passing values from the outer loop to the inner loop. A simplified version of my procedure is:

Option Explicit

Sub A()

Dim t as integer

t=0

Do

lines of code

Worksheets (1).Range("A1").Value = t

Do While (Condition is Satisfied)

lines of code

Worksheets (1).Range("A2").Value = t

Loop

t = t + 1

Loop Until t = 41

End Sub

The purpose of the program is to write the final value of t in the outer loop in Cell A1, and the final value of t in the inner loop in Cell A2.
Both values should equal 40. However, the value of 40 is placed in Cell A1 and the value of 0 is placed in Cell 2. Apparently the value of t is not being passed from the outer loop to the inner loop.

Is there anyone that can help me solve this problem?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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