View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default A Sub/Function to cause another Sub/Function to Exit

Guess I didn't finish putting in the exit function statements:

Function newCell() as Boolean
Dim whiteSpace As Object
Dim curCell As Integer

Set whiteSpace = CreateObject("VBScript.RegExp")
whiteSpace.IgnoreCase = True
whiteSpace.Pattern = "^\s*$"

If ActiveSheet.name < "myForm" Then Sheet2.Activate
If Not ActiveCell.Address = "$L$19" Then Range("L19").Select

For curCell = 19 To 45
cells(curCell,"L").Select
If (whiteSpace.test(ActiveCell.value)) Then
NewCell = True
Exit Function
ElseIf curCell = 45 Then
MsgBox "No more line entries available." & _
Chr(13) & "Please combine your entries and resubmit."
NewCell = False
Exit Function
End If
Next
NewCell = True
End Function

With the Exit functions added, it should never reach that statement.

--
Regards,
Tom Ogilvy


"IT_roofer" wrote:

"Tom Ogilvy" wrote:

Perhaps something like this:

Sub DumpData()

' existing code
if not newCell then exit sub
' existing code

End sub


Function newCell() as Boolean
Dim whiteSpace As Object
Dim curCell As Integer

Set whiteSpace = CreateObject("VBScript.RegExp")
whiteSpace.IgnoreCase = True
whiteSpace.Pattern = "^\s*$"

If ActiveSheet.name < "myForm" Then Sheet2.Activate
If Not ActiveCell.Address = "$L$19" Then Range("L19").Select

For curCell = 19 To 45
cells(curCell,"L").Select
If (whiteSpace.test(ActiveCell.value)) Then
NewCell = True
ElseIf curCell = 45 Then
MsgBox "No more line entries available." & _
Chr(13) & "Please combine your entries and resubmit."
NewCell = False
End If
Next
NewCell = True
End Function

--
Regards,
Tom Ogilvy



Thank you for the suggestion. I will try it. One question: doesn't the
"NewCell = True" statement at the end override the "NewCell = False"
statement in the "ElseIf curCell = 45" - or is that just to reset "NewCell"
when the For loop is over?