Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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 ]



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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Need to open the Function Arguments window from VBA for a user defined function. [email protected] Excel Programming 0 June 20th 06 03:53 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 10:02 PM.

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

About Us

"It's about Microsoft Excel"