ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling (https://www.excelbanter.com/excel-programming/395836-error-handling.html)

Sarah at DaVita

Error handling
 
I have a workbook with many sheets. I want to look for specific data and
then do some action. I can get the macro to work until it cannot find what I
am looking for. How do I tell it that if it doesn't find what it was looking
for then to go to a different sub routine? Ie: I am looking for 6301 in
column A if that is not present end sub acct_6301 and go to sub acct_6326
which is looking for a different account if 6326 is found then do something
and then go look for the next one. Clear as mud? Any help would be
appreciated.

Dave Peterson

Error handling
 
You could change your Subroutines to Functions that return a boolean value
(true/false).

Function acct_6301(someparms as sometypeofvariables) as boolean

if somethingisn'tfound then
acct_6301 = false
else
acct_6301 = true
end if
End Function

Then you could call the function.

Dim OkToContinue as boolean
....
oktocontinue = acct_6301(something)
if oktocontinue then
'it was found
else
'it wasn't found
end if
========

Alternatively, you could set up a public variable:

Public OkToContinue as boolean
and set that to true/false depending on what you find.


Sub Acct_6301()

if something then
oktocontinue = true
else
oktocontinue = false
end if

End sub

And your calling procedure would do:

Call acct_6301(maybe passed parms here???)
if oktocontinue then
'do something
else
call acct_6301
if oktocontinue then
'ok so far
else
call acct_6326
if .....

======
Muddier than you thought?





Sarah at DaVita wrote:

I have a workbook with many sheets. I want to look for specific data and
then do some action. I can get the macro to work until it cannot find what I
am looking for. How do I tell it that if it doesn't find what it was looking
for then to go to a different sub routine? Ie: I am looking for 6301 in
column A if that is not present end sub acct_6301 and go to sub acct_6326
which is looking for a different account if 6326 is found then do something
and then go look for the next one. Clear as mud? Any help would be
appreciated.


--

Dave Peterson

Halim

Error handling
 
Try to modify this one or keepit as is if fit you want:

Sub acct_6301()
Dim Mydat As String
Dim Find1 As Object

Mydat = "6301"
Set Find1 = Cells.Find(Mydat, LookIn:=xlValues)
If Not Find1 Is Nothing Then 'if exist at least one then continue your
code
' your code here---
Else
Call acct_6326
End If

End Sub

--
Regards,

Halim

"Sarah at DaVita" wrote:
I have a workbook with many sheets. I want to look for specific data and
then do some action. I can get the macro to work until it cannot find what I
am looking for. How do I tell it that if it doesn't find what it was looking
for then to go to a different sub routine? Ie: I am looking for 6301 in
column A if that is not present end sub acct_6301 and go to sub acct_6326
which is looking for a different account if 6326 is found then do something
and then go look for the next one. Clear as mud? Any help would be
appreciated.



All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com