Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Lee Harris
 
Posts: n/a
Default How easy is it to loop in VBA based on cell contents?

I have a function in code that I added via the built in form designer

Option Explicit
Private Sub CommandButton1_Click()
Application.Calculate
End Sub

I access that with Alt-F11


How easy is it for me to change this such that after the relevant
Application.Calculate, it looks at the value in a specific cell on a
specific sheet, and if it's 1, then do Application.Calculate again, up to a
maximum of N times


I'm just not sure of the syntax when referring to cells etc

My application selects a football play from a list based on the game
situation, but there are specific situations where certain plays can't be
called. It would be a pain to code that in to the randomising on the sheets,
so what I'm trying to do essentially in quasi-code is


Private Sub ClickEventHandler()

iter=0

Do Application.Calculate
iter++
While Rules$a$1 AND iter < N
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gary''s Student
 
Posts: n/a
Default How easy is it to loop in VBA based on cell contents?

How about:

Sub Macro1()
For i = 1 To 37
j = Sheets("Sheet3").Range("A1").Value
If j = 1 Then
Exit For
Else
Application.Calculate
End If
Next
End Sub

--
Gary's Student


"Lee Harris" wrote:

I have a function in code that I added via the built in form designer

Option Explicit
Private Sub CommandButton1_Click()
Application.Calculate
End Sub

I access that with Alt-F11


How easy is it for me to change this such that after the relevant
Application.Calculate, it looks at the value in a specific cell on a
specific sheet, and if it's 1, then do Application.Calculate again, up to a
maximum of N times


I'm just not sure of the syntax when referring to cells etc

My application selects a football play from a list based on the game
situation, but there are specific situations where certain plays can't be
called. It would be a pain to code that in to the randomising on the sheets,
so what I'm trying to do essentially in quasi-code is


Private Sub ClickEventHandler()

iter=0

Do Application.Calculate
iter++
While Rules$a$1 AND iter < N
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Lee Harris
 
Posts: n/a
Default How easy is it to loop in VBA based on cell contents?


"Gary''s Student" wrote in message
...
How about:

Sub Macro1()
For i = 1 To 37
j = Sheets("Sheet3").Range("A1").Value
If j = 1 Then
Exit For
Else
Application.Calculate
End If
Next
End Sub

--
Gary's Student



thanks, that looks great, I just wasn't sure what the syntax was though I
guessed the approximate format!


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben
 
Posts: n/a
Default How easy is it to loop in VBA based on cell contents?

Shouldn't it read?

If J < 1 Then

You wanted to iterate if A1 was 1 and not if something else.


Gord Dibben Excel MVP

On Fri, 25 Nov 2005 01:11:09 GMT, "Lee Harris" wrote:


"Gary''s Student" wrote in message
...
How about:

Sub Macro1()
For i = 1 To 37
j = Sheets("Sheet3").Range("A1").Value
If j = 1 Then
Exit For
Else
Application.Calculate
End If
Next
End Sub

--
Gary's Student



thanks, that looks great, I just wasn't sure what the syntax was though I
guessed the approximate format!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I conditionally delete rows based on cell contents? John Chan Excel Worksheet Functions 3 May 17th 23 03:45 AM
Using contents of a cell in a formula Mike Excel Discussion (Misc queries) 4 June 9th 05 03:10 AM
Copy cell format to cell on another worksht and update automatical kevinm Excel Worksheet Functions 21 May 19th 05 11:07 AM
Function syntax to compare cell contents ES Excel Worksheet Functions 2 May 18th 05 03:53 PM
Sum numbers based on the contents of another cell Doreen Excel Worksheet Functions 5 May 5th 05 04:41 PM


All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"