ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Looping till condition is satisfied? (https://www.excelbanter.com/excel-worksheet-functions/160889-looping-till-condition-satisfied.html)

Jo[_2_]

Looping till condition is satisfied?
 
I have this macro's code:

Dim SCell As Integer
Do Until SCell.Value = 1
If SCell.Value < 1 Then

Range("J24").Select
Calculate
End If
Loop

Where SCell has a formula like this: "if (A2<A3,1,0)" and A2 has a
random number while A3 is a fixed value. I want the macro once clicked
to keep changing A2 till SCell formula is 1. So the loop could run 5
times or 500 times.

Is there something wrong in the code above?

Thanks,
Jo


JNW

Looping till condition is satisfied?
 
Your code isn't actually changing cell A2. all it is doing is recalculating
the sheet. Is this what you wanted to do? Is there something else that is
changing A2?
--
JNW


"Jo" wrote:

I have this macro's code:

Dim SCell As Integer
Do Until SCell.Value = 1
If SCell.Value < 1 Then

Range("J24").Select
Calculate
End If
Loop

Where SCell has a formula like this: "if (A2<A3,1,0)" and A2 has a
random number while A3 is a fixed value. I want the macro once clicked
to keep changing A2 till SCell formula is 1. So the loop could run 5
times or 500 times.

Is there something wrong in the code above?

Thanks,
Jo



Jo[_2_]

Looping till condition is satisfied?
 
On Oct 4, 11:17 am, JNW wrote:
Your code isn't actually changing cell A2. all it is doing is recalculating
the sheet. Is this what you wanted to do? Is there something else that is
changing A2?
--
JNW



"Jo" wrote:
I have this macro's code:


Dim SCell As Integer
Do Until SCell.Value = 1
If SCell.Value < 1 Then


Range("J24").Select
Calculate
End If
Loop


Where SCell has a formula like this: "if (A2<A3,1,0)" and A2 has a
random number while A3 is a fixed value. I want the macro once clicked
to keep changing A2 till SCell formula is 1. So the loop could run 5
times or 500 times.


Is there something wrong in the code above?


Thanks,
Jo- Hide quoted text -


- Show quoted text -


When it recalculates the sheet, the random number does change and so
SCell does check the condition to see if satisfied or not. The macro
has to stop once SCell is satisfied.
That is all actually.


Mark Lincoln

Looping till condition is satisfied?
 
On Oct 4, 11:28 am, Jo wrote:
On Oct 4, 11:17 am, JNW wrote:




You Dim an Integer variable SCell, then do nothing with it. Thus it
is always zero.

If you have a cell named "SCell" you can write something like this:

Range("J24").Select

Do Until Range("SCell").Value = 1
Calculate
Loop


Your code isn't actually changing cell A2. all it is doing is recalculating
the sheet. Is this what you wanted to do? Is there something else that is
changing A2?
--
JNW


"Jo" wrote:
I have this macro's code:


Dim SCell As Integer
Do Until SCell.Value = 1
If SCell.Value < 1 Then


Range("J24").Select
Calculate
End If
Loop


Where SCell has a formula like this: "if (A2<A3,1,0)" and A2 has a
random number while A3 is a fixed value. I want the macro once clicked
to keep changing A2 till SCell formula is 1. So the loop could run 5
times or 500 times.


Is there something wrong in the code above?


Thanks,
Jo- Hide quoted text -


- Show quoted text -


When it recalculates the sheet, the random number does change and so
SCell does check the condition to see if satisfied or not. The macro
has to stop once SCell is satisfied.
That is all actually.- Hide quoted text -

- Show quoted text -





All times are GMT +1. The time now is 11:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com