![]() |
End Double Sub
I'm having difficulties Ending a macro. a Sub calls an other Sub that also investigates if a value alread exists in a range of cells. If it doesnt exist, the main sub can go on *else both Subs has to end* The last part doesn work, i can only stop the sub I'm working in. How to solve this problem? Th -- Zur ----------------------------------------------------------------------- Zurn's Profile: http://www.excelforum.com/member.php...fo&userid=1464 View this thread: http://www.excelforum.com/showthread.php?threadid=26724 |
End Double Sub
hi,
not sure because i haven't seen your code but i would say combine the two macros. put the called macro inside the main macro as an if then else. that way you only have 1 macro to stop. -----Original Message----- I'm having difficulties Ending a macro. a Sub calls an other Sub that also investigates if a value already exists in a range of cells. If it doesnt exist, the main sub can go on, *else both Subs has to end* The last part doesn work, i can only stop the sub I'm working in. How to solve this problem? Thx -- Zurn ---------------------------------------------------------- -------------- Zurn's Profile: http://www.excelforum.com/member.php? action=getinfo&userid=14645 View this thread: http://www.excelforum.com/showthread...hreadid=267249 . |
End Double Sub
Change your procedure from a sub routine to a function.
Make the return type a Boolean then return true if found and false in not. The function would look sometjhing like the following. This function will seach a column (column C in the spreadsheet) from row 10 to row 20. If it finds the value it exits the function and returns True. If it completes the search without finding the item, it exits the function and returns false. Public Function mysearch(myParam As myParamType) As Boolean curRow=10 maxRow=20 myCol=3 Do While curRow < maxRow mVal=worksheets(1).cells(curRow, myCol).value if(myVal=myParam)then mysearch=True exit sub endif curRow=curRow+1 loop mysearch=False end function In your calling function have the following code: if(not mysearch(desiredValue))then exit sub endif I hope that is clear. Kevin -----Original Message----- I'm having difficulties Ending a macro. a Sub calls an other Sub that also investigates if a value already exists in a range of cells. If it doesnt exist, the main sub can go on, *else both Subs has to end* The last part doesn work, i can only stop the sub I'm working in. How to solve this problem? Thx -- Zurn ---------------------------------------------------------- -------------- Zurn's Profile: http://www.excelforum.com/member.php? action=getinfo&userid=14645 View this thread: http://www.excelforum.com/showthread...hreadid=267249 . |
All times are GMT +1. The time now is 11:06 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com