Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default 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.

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
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error Handling JT Excel Programming 1 April 6th 06 03:20 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error handling V. Roe Excel Programming 2 February 27th 04 08:04 PM


All times are GMT +1. The time now is 05:25 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"