Do Until Question

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
I have a Do until statement wrapped in an If statement and this is the Do until code I am using:
Code:
DEPI = Sheets("MTN").Range("A1").End(xlDown).row    Set findrange = Sheets("MTN").Range("A1:A" & DEPI)
    Set foundcell = findrange.Find(What:=Sheets("MTN").Range("C1").Value, LookIn:=xlValues, LookAt:=xlWhole)
     
    Do Until foundcell Is Nothing
        Sheets("MTN").Range("C1").Value = Sheets("MTN").Range("C1").Value + 1
        
        Loop

I have a range of Numbers in Column A and a number in C1. I want to increase the value in a cell C1 by 1 until the value in C1 is not found with in my specified range. When I run the Macro, it just keeps looping, somehow I have created a continuous loop.
If anyone can help me figure out how to accomplish my goal, I would be extremely grateful
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
When I run the Macro, it just keeps looping, somehow I have created a continuous loop.

Because foundcell does not change inside the Do Until loop.

Ostensibly, you want:

Code:
Do
    Set foundcell = findrange.Find(What:=Sheets("MTN").Range("C1").Value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not foundcell Is Nothing Then Sheets("MTN").Range("C1").Value = Sheets("MTN").Range("C1").Value + 1
Loop Until foundcell is Nothing
 
Last edited:
Upvote 0
Another way....

Code:
Dim n As Long
....
n = Sheets("MTN").Range("C1").Value
Do
    Set foundcell = findrange.Find(What:=n, LookIn:=xlValues, LookAt:=xlWhole)
    If foundcell Is Nothing Then Exit Do
    n = n + 1
Loop
Sheets("MTN").Range("C1").Value = n

Change n to Double if MTN!C1 might not be an integer.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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