Results 1 to 9 of 9

List all formulas in active workbook

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,982

    List all formulas in active workbook

    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
    Attached Files Attached Files
    I know I'm not stupid, but I suspect I'm a lot stupider than I think I am

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. List files in directory of the active workbook
    By plans in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2017, 06:09 PM
  2. Open Another Workbook from Active Workbook but stay on Active Workbook.
    By Tona in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2014, 06:33 AM
  3. [SOLVED] Code to detect previous active workbook instead of current active workbook
    By kosherboy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-25-2014, 01:58 AM
  4. Vba toChange all formulas source in worksheet to the active workbook
    By Bpd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2013, 10:16 PM
  5. Adding and Deleting to a list in a workbook other than the active workbook.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2013, 11:00 AM
  6. [SOLVED] Active X List box cnhanges size each time I open the workbook?
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-24-2013, 07:14 AM
  7. VBA macro for hyperlink to active workbook in the active workbook path
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-10-2013, 05:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1