title: VBA to search a specific worksheet for errors and pass back result to main macro
body: <p>I need a macro which will search for formula errors in a specific worksheet in a workbook.  This needs to work in multiple different workbooks with different worksheet names in each book.  Once it has completed the check, I want it to define a variable called SheetErrors as "1" if there are errors or "0" if there aren't any.  If it is "1", it then needs to be passed back to a main macro as I want it to exit the sub and display a message box stating that spreadsheet contains errors.</p>
  
  <p>I have written the code below to find the errors:</p>
  
  <pre><code>Sub Error_Finder()
  
  Dim celltxt As String
  Dim SheetErrors As String
  
  celltxt = ActiveSheet.Range("A:FA").Text
  
  
  
  If InStr(1, celltxt, "#NULL!") Or _
     InStr(1, celltxt, "#NUM!") Or _
     InStr(1, celltxt, "#REF!") Or _
     InStr(1, celltxt, "#VALUE!") Then
     SheetErrors = "1"
     Else
     SheetErrors = "0"
  
  
  End Sub
  </code></pre>
  
  <p>I can't find anything useful to me on Google for passing the SheetErrors variable back to the main macro.  Any light you can shed on it would be gratefully received, also, I'm pretty new to VBA, so if there is a better way of doing what I have done above, please let me know.</p>
  
  <p>Thank you,</p>
  
  <p>P</p>