Help with macro?

  • Thread starter Thread starter Jo
  • Start date Start date
J

Jo

Here is the macro code:

Dim SCell As Integer

Do Until SCell.Value = 1
If SCell.Value <> 1 Then

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

where SCell checks a condition like this: "if(A2>A3,1,0)" and A2 has
RAND in it so everytime sheet is calculated by changing RAND, SCell's
condition is checked. The macro's loop might runs one time or 500
times but it must stop when SCell=1

Thanks,
Jo
 
Probably should be

Dim SCell As Integer

Do Until Activeell.Value = 1
If Activecell.Value <> 1 Then

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


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Probably should be

Dim SCell As Integer

Do Until Activeell.Value = 1
If Activecell.Value <> 1 Then

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

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)











- Show quoted text -

It is working but it is NOT stopping when SCell is 1?! What could be
missing?
 
I put RAND in A2, 3 in A3, and =IF(A2>A3,1,0) in J24. SCell value
remains at 0. It appears never to reach 1.
 
There are some things that I'm not following

: Dim SCell As Integer
:
: Do Until SCell.Value = 1
So the above says to do this loop until the value of SCell = 1

: If SCell.Value <> 1 Then
Why would you need this line, the loop requirement above says that SCell <>
1 or we would not execute the loop

: Range("J24").Select
So if SCell value <> 1 (requirement to be in loop) then select Range
("J24"). Seems like everytime you run the loop, you are selecting the same
cell

: Calculate
: End If
: Loop

If you just want to loop till you hit 1, this should work. If there is
something else you are trying to do, then this will need to be modified

Dim SCell As Integer

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

Paul D

: Here is the macro code:
:
: Dim SCell As Integer
:
: Do Until SCell.Value = 1
: If SCell.Value <> 1 Then
:
: Range("J24").Select
: Calculate
: End If
: Loop
:
: where SCell checks a condition like this: "if(A2>A3,1,0)" and A2 has
: RAND in it so everytime sheet is calculated by changing RAND, SCell's
: condition is checked. The macro's loop might runs one time or 500
: times but it must stop when SCell=1
:
: Thanks,
: Jo
:
 
I put RAND in A2, 3 in A3, and =IF(A2>A3,1,0) in J24. SCell value
remains at 0. It appears never to reach 1.




- Show quoted text -

Trust me, I didn't post the example I have as it is but just something
simple to make my point. Actually, in my application, the if-condition
gets satisfied every # of times as I see it but want the macro to STOP
when SCell gets 1!

With your code, I can see SCell is hitting one but it keeps running!

What do you think I should add to the code?
 
Back
Top