View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Zone[_3_] Zone[_3_] is offline
external usenet poster
 
Posts: 373
Default A Sub/Function to cause another Sub/Function to Exit

IT,
I like to set the function's return value at the top if possible so that I'm
sure what state the function starts out with. But you could do it either my
way or Tom's way. Either way, you do need to set the function's value to
something in any case. In my test, if you never set the function's return
value, it just returns False. The difference between a sub and a function
is really very simple. A function can return a value. A sub cannot. James
"IT_roofer" wrote in message
...
"Zone" wrote:

IT, make newCell a Function so it can return a value to the calling
routine.
James

Function newCell() as Boolean
newCell=True

<snip

ElseIf curCell 45 Then
MsgBox "No more line entries available." & _
Chr(13) & "Please combine your entries and resubmit."
NewCell=False
Exit For
Else
ActiveCell.Offset(1, 0).Select
End If
Next
End Function




Thanks Guys for the suggestions.

I noticed Tom put "newCell = True" after the For loop and Zone/James put
it
ahead of the For loop. Do I have to declare newcell = True/False outside
of
the For loop at all?

Tom: I added in an "Exit For" (in code below) to get it to stop cycling
through the cells to cell L45. There's a locked cell @L46 and it generated
an
error about accessing locked cells. Otherwise your code worked perfect.
Thanks!

Zone/James: I still don't quite get the difference between a function and
a
sub, but i guess that's part of learning! Maybe you could shed some light?

(code)
If (whiteSpace.test(ActiveCell.value)) Then
newCell = True
Exit For '<======[ THIS ]