End Double Sub

  • Thread starter Thread starter Zurn
  • Start date Start date
Z

Zurn

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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top