I have the macro below, which I cobbled together many years ago and use often, to list every formula in the workbook, with the address of said formula. I've noticed, belatedly, that it's producing an error. In the attachment I have sheets "Unique Values", which contains formulas and "Data", which has no formulas, just data. The sheet "Formulalist" is added by the macro, and lists all the formulas in the workbook. the error it's creating is for "Data" it's listing the same formulas as "Unique Values", and I can't figure out why. The macro is in the workbook and pasted below. I'd appreciate any help I can get on this.
Sub Wkbook_ListFormulas()
'Purpose : Lists all formulas and formula locations in the workbook in a new sheet.
Dim sht As Worksheet
Dim Shtname
Dim MyRng As Range
Dim NewRng As Range
Dim Place As Range
Dim c As Range
Shtname = "Formulalist"
' Add a new worksheet to end of right
If [not(isref(FormulaList!A1))] Then
ActiveWorkbook.Worksheets.Add After:=Worksheets(Worksheets.Count)
Else
Sheets("Formulalist").Activate
End If
'Set up the sheet
With ActiveSheet
.Cells.Delete 'If there was an old formulalist, this wipes it out
.Range("A7:D7").Value = [{"Sheet Name","Cell Address","Formula","Inconsistent Formula"}]
.Range("D1:D5") = Application.Transpose(Array("VLookups", "IFs", "SubTotals", "MAX or MIN", "Sums"))
.Range("D1").Interior.ColorIndex = 8
.Range("D2").Interior.ColorIndex = 15
.Range("D3").Interior.ColorIndex = 4
.Range("D4").Interior.ColorIndex = 6
.Range("D5").Interior.ColorIndex = 24
.Range("C3").Value = "Legend"
.Range("C3").Font.Bold = True
.Name = Shtname
End With
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> Shtname Then
Set MyRng = sht.UsedRange 'limit the search to the UsedRange
On Error Resume Next 'in case there are no formulas
Set NewRng = MyRng.SpecialCells(xlCellTypeFormulas)
For Each c In NewRng
Set Place = Sheets(Shtname).Range("A65536").End(xlUp).Offset(1, 0)
Place.Value = sht.Name 'places the sheet name containing the formula in column A
Place.Offset(0, 1).Value = _
Application.WorksheetFunction.Substitute(c.Address, "$", "") 'places the cell address, minus the "$" signs, containing the formula in column B
Place.Offset(0, 2).Value = " " & c.Formula 'Mid(C.Formula, 2, (Len(C.Formula))) 'places the formula minus the '=' sign in column C
Place.Offset(0, 3).Value = c.Errors.Item(xlInconsistentFormula).Value
Next c
End If
Next sht
Sheets(Shtname).Activate
With ActiveSheet
Set MyRange = .Range("A7").CurrentRegion
LastRow = MyRange.Rows.Count + 6
'Color the common formulas
.AutoFilterMode = False
.Range("A7:D7").AutoFilter
.Range("A7:D7").AutoFilter Field:=3, Criteria1:="==VLookup*", Operator:=xlAnd
.Range("C8:C" & LastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 8 'Light Blue
.Range("A7:D7").AutoFilter Field:=3, Criteria1:="==IF*", Operator:=xlAnd
.Range("C8:C" & LastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 15 'Light Gray
.Range("A7:D7").AutoFilter Field:=3, Criteria1:="==Subtotal*", Operator:=xlAnd
.Range("C8:C" & LastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 4 'Light Green
.Range("A7:D7").AutoFilter Field:=3, Criteria1:="==MAX*", Operator:=xlOr, Criteria2:="==MIN*"
.Range("C8:C" & LastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 6 'Yellow
.Range("A7:D7").AutoFilter Field:=3, Criteria1:="==Sum*", Operator:=xlAnd
.Range("C8:C" & LastRow).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = 24 'Light Purple
.ShowAllData
.Range("A7:D7").AutoFilter Field:=4, Criteria1:="=True", Operator:=xlAnd
.Range("C8:D" & LastRow).SpecialCells(xlCellTypeVisible).Font.ColorIndex = 3 'Red
.Range("A7:D7").AutoFilter Field:=4, Criteria1:="=False", Operator:=xlAnd
.Range("D8:D" & LastRow).SpecialCells(xlCellTypeVisible).ClearContents
.ShowAllData
.Range("A7:D7").Font.Bold = True
.Range("A1,C3").HorizontalAlignment = xlCenter
.Columns("A:D").AutoFit
If .Columns("A").ColumnWidth > 150 Then .Columns("A").ColumnWidth = 150 'Keeps the formula column from getting too wide
With .Range("A7:D7").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
End With
With ActiveWindow
.SplitRow = 7
.FreezePanes = True
.DisplayGridlines = False
End With
End Sub
Bookmarks