View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Out of Stack Space error


There are too many unexplained variables in your sub.
It is therefore difficult to understand what is going on.
The following is one way it could be set up...
'-------------------------------------
Option Explicit

Public Sub Jim(ByRef NoToFill As Long, ByRef FirstDate As Date, _
ByRef SecondDate As Date)
Dim i As Long

' keep things within reason
For i = 2 To WorksheetFunction.Max(NoToFill, 1000)

If i = 2 Then
Mary1
ElseIf Worksheets("Sheet2").Cells(i, 2).Value < FirstDate Then
Fred
ElseIf (Worksheets("Sheet2").Cells(i, 2).Value = FirstDate) And _
(Worksheets("Sheet2").Cells(i, 2).Value <= SecondDate) Then
Jane
End If

Next i
End Sub
'-----------------------------------
Jim Cone
San Francisco, USA


"JimFor" wrote in message
...
Hi,
I have a program which has a User form. and which uses multiple IF statements
to determine what to do. The user enters FirstDate, SecondDate and number of
transactions to look at (NoToFill). It uses a counter to check the cell value
on one sheet and, depending on what that cell value is, does a variety of
things. Hence, the multiple IF statements. As of now I have been unable to
execute any IF statement beyond the first two. Here is a brief bit of code:
The format for the cells is General.


'Main program
Public Sub Jim()
Count = 1
For i = 1 To NoToFill
Count = Count + 1
'If first transaction then set up first line on Sheet3
If Count = 2 Then Mary1
'If other than first transactions and date on sheet2 before date entered by
user go to Fred
If Worksheets("Sheet2").Cells(Count, 2) < FirstDate Then Fred
'If other than first transactions and date on sheet2 within dates entered by
user go to Jane
If Worksheets("Sheet2").Cells(Count, 2) = FirstDate And
Worksheets("Sheet2").Cells(Count, 2) <= SecondDate Then Jane
Next i
End Sub


I can get results from "Mary1" and "Fred" but "Jane" never seems to process
anything. The error I receive is an Out of Stack Space error. Mary1 and Fred
do process if I do not enter dates. However, when I enter dates and the
program is supposed to calculate based upon the date criteria, I get an Out of
Stack error and an arrow appears next to the If Count=2 Then Mary1 line. Can
anyone tell me what might be wrong and what I should do to correct it?
Thanks