MS Office Forum / Excel / Programming / August 2008
Macro to find and log all formula errors on all sheets
|
|
Thread rating:  |
Adnan - 15 Aug 2008 21:42 GMT Is there a code that goes thru each sheet of the work book and looks for formula errors (any type) and then record the name of the file and type of error into a different workbook?
I have a workbook that has a list of paths to lots of other workbooks, in this workbook I want to create a macro that open each and everyone of those workbooks listed and look for any type of formula errors (i.e.: #VALUE or #DIV/O, or #N/A etc…) in them.
Your help is greatly appreciated, Adnan
Barb Reinhardt - 16 Aug 2008 02:28 GMT Try this
Sub Test() Dim aWB As Workbook Dim myWB As Workbook Dim r As Range
Set aWB = ActiveWorkbook Set myWB = Workbooks.Add Set myWS = myWB.Worksheets(1) myWS.Name = "Errors Found" lrow = 1 myWS.Cells(1, 1) = "Workbook Name" myWS.Cells(1, 2) = "Worksheet Name" myWS.Cells(1, 3) = "Cell Address" myWS.Cells(1, 4) = "Cell Value" myWS.Cells(1, 5) = "Cell Formula"
For Each WS In aWB.Worksheets For Each r In WS.UsedRange If IsError(r) Then lrow = lrow + 1 myWS.Cells(lrow, 1) = aWB.Name myWS.Cells(lrow, 2) = WS.Name myWS.Cells(lrow, 3) = r.Address myWS.Cells(lrow, 4) = r.Value myWS.Cells(lrow, 5) = "'" & r.FormulaR1C1 End If Next r Next WS
End Sub
 Signature HTH, Barb Reinhardt
> Is there a code that goes thru each sheet of the work book and looks for > formula errors (any type) and then record the name of the file and type of [quoted text clipped - 7 lines] > Your help is greatly appreciated, > Adnan Adnan - 16 Aug 2008 09:02 GMT Barb,
Thanks for your help --- This code works great but finds errors only in the work book that is open, I need something like this: http://cid-642741f4bfb02015.skydrive.live.com/self.aspx/Public/FindError.xls
Thank you, Adnan
> Try this > [quoted text clipped - 40 lines] > > Your help is greatly appreciated, > > Adnan Barb Reinhardt - 16 Aug 2008 13:23 GMT I'm going to assume that you have the path names listed in column A starting in Row 2.
Sub Test() Dim aWB As Workbook Dim oWB As Workbook Dim oWS As Worksheet Dim myRange As Range Dim lRow As Range Dim myLink As Range Dim myWB As Workbook Dim r As Range
Set aWB = ActiveWorkbook Set aWS = ActiveSheet Set myRange = aWS.Cells(2, 1) 'Sets beginning of range of links lRow = aWS.Cells(aWS.Rows.Count, myRange.Row).End(xlUp).Row Set myRange = myRange.Resize(lRow - myRange.Row + 1, 1)
Set myWB = Workbooks.Add Set myWS = myWB.Worksheets(1) myWS.Name = "Errors Found" lRow = 1 myWS.Cells(1, 1) = "Workbook Name" myWS.Cells(1, 2) = "Worksheet Name" myWS.Cells(1, 3) = "Cell Address" myWS.Cells(1, 4) = "Cell Value" myWS.Cells(1, 5) = "Cell Formula"
For Each myLink In myRange Set oWB = Workbooks.Open(myLink.Value) If Not oWB Is Nothing Then For Each WS In oWB.Worksheets For Each r In WS.UsedRange If IsError(r) Then lRow = lRow + 1 myWS.Cells(lRow, 1) = aWB.Name myWS.Cells(lRow, 2) = WS.Name myWS.Cells(lRow, 3) = r.Address myWS.Cells(lRow, 4) = r.Value myWS.Cells(lRow, 5) = "'" & r.FormulaR1C1 End If Next r Next WS oWB.Close End If Next myLink
End Sub
 Signature HTH, Barb Reinhardt
> Barb, > [quoted text clipped - 49 lines] > > > Your help is greatly appreciated, > > > Adnan Adnan - 16 Aug 2008 14:36 GMT Barb,
I'm gettin an error. See it here: http://cid-642741f4bfb02015.skydrive.live.com/self.aspx/Public/OfficeCommunity/O nSheets.xls
v/r Adnan
> I'm going to assume that you have the path names listed in column A starting > in Row 2. [quoted text clipped - 99 lines] > > > > Your help is greatly appreciated, > > > > Adnan Barb Reinhardt - 16 Aug 2008 15:35 GMT I don't make it a habit to download worksheets from the net. What is the error and where? I'm guessing it's in the workbook.open line.
Before that, put debug.print mylink.address, "value=";mylink.value on error resume next after the workbook open put on error goto 0
 Signature HTH, Barb Reinhardt
> Barb, > [quoted text clipped - 107 lines] > > > > > Your help is greatly appreciated, > > > > > Adnan Adnan - 16 Aug 2008 18:34 GMT It primts with an error debug message 'Object variale or with block variable not set'. When hit Debug, it takes me to this line of code: lRow = aWS.Cells(aWS.Rows.Count, myRange.Row).End(xlUp).Row
> I don't make it a habit to download worksheets from the net. What is the > error and where? I'm guessing it's in the workbook.open line. [quoted text clipped - 116 lines] > > > > > > Your help is greatly appreciated, > > > > > > Adnan Barb Reinhardt - 16 Aug 2008 19:48 GMT Change myRange.row to myRange.column.
 Signature HTH, Barb Reinhardt
> It primts with an error debug message 'Object variale or with block variable > not set'. When hit Debug, it takes me to this line of code: lRow = [quoted text clipped - 120 lines] > > > > > > > Your help is greatly appreciated, > > > > > > > Adnan Adnan - 17 Aug 2008 08:47 GMT Still not working, same error.
> Change myRange.row to myRange.column. > [quoted text clipped - 122 lines] > > > > > > > > Your help is greatly appreciated, > > > > > > > > Adnan Per Jessen - 17 Aug 2008 14:56 GMT Hi
Change this line :
Dim lRow As Range
to
Dim lRow As Long
Regards, Per
> Still not working, same error. > [quoted text clipped - 133 lines] >> > > > > > > > Your help is greatly appreciated, >> > > > > > > > Adnan Adnan - 18 Aug 2008 08:40 GMT Thank you Per, it worked.
> Hi > [quoted text clipped - 146 lines] > >> > > > > > > > Your help is greatly appreciated, > >> > > > > > > > Adnan
|
|
|