Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / October 2007

Tip: Looking for answers? Try searching our database.

Looping till condition is satisfied?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jo - 04 Oct 2007 16:00 GMT
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 - 04 Oct 2007 16:17 GMT
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?
Signature

JNW

> I have this macro's code:
>
[quoted text clipped - 16 lines]
> Thanks,
> Jo
Jo - 04 Oct 2007 16:28 GMT
> 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
[quoted text clipped - 24 lines]
>
> - 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 - 04 Oct 2007 21:43 GMT
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
[quoted text clipped - 31 lines]
>
> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.