Generate a Table of Formula References

IluvPivots

Board Regular
Joined
Feb 13, 2007
Messages
141
Office Version
  1. 2016
Is there a way to generate a table that lists all the formulas and their references for an entire workbook? Similar to what is generated when the "Find" feature is used. (see image) It would be nice if the Find results could be exported or copied, but I cannot figure that one out. I searched for the name of a specific sheet (BALSHEET), the results show which other sheet/cells reference the searched word (BALSHEET). There are several cross referenced formulas within this workbook and I need to create a table to easily identify. help??
 

Attachments

  • FindResutls1.png
    FindResutls1.png
    68.7 KB · Views: 19

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi there,

Set up a blank sheet with the same layout I have done in the attached image, change the variables I have marked in the following macro to your specific needs and then try the following:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wb As Workbook
    Dim wsDestin As Worksheet, wsSrc As Worksheet
    Dim rngMyCell As Range
    Dim strFindWhat As String, strFormula As String
    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    Set wb = ThisWorkbook
    Set wsDestin = wb.Sheets("Sheet1") '<-Name of sheet to put the results. Change to suit if necessary.
    strFindWhat = wsDestin.Range("B1").Value '<-Cell in sheet 'wsDestin' that has the text to search within formulas for. Change to suit if necessary.
    
    If WorksheetFunction.CountA(wsDestin.Cells) > 0 Then
        lngPasteRow = wsDestin.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    Else
        lngPasteRow = 3 '<-Starting row for the output if there's no data in 'wsDestin'. Change to suit if necessary.
    End If
    
    For Each wsSrc In wb.Sheets
        If wsSrc.Name <> wsDestin.Name Then
            For Each rngMyCell In wsSrc.UsedRange
                If rngMyCell.HasFormula = True Then
                    strFormula = rngMyCell.Formula
                    If InStr(strFormula, strFindWhat) > 0 Then
                        wsDestin.Range("A" & lngPasteRow).Value = wb.Name
                        wsDestin.Range("B" & lngPasteRow).Value = wsSrc.Name
                        On Error Resume Next
                            wsDestin.Range("C" & lngPasteRow).Value = rngMyCell.Name.Name
                        On Error GoTo 0
                        wsDestin.Range("D" & lngPasteRow).Value = rngMyCell.Address
                        wsDestin.Range("E" & lngPasteRow).Value = rngMyCell.Value
                        wsDestin.Range("F" & lngPasteRow).Value = "'" & rngMyCell.Formula
                        lngPasteRow = lngPasteRow + 1
                    End If
                End If
            Next rngMyCell
        End If
    Next wsSrc
    
    Application.ScreenUpdating = True
    
    MsgBox "Done", vbInformation

End Sub

Regards,

Robert
 

Attachments

  • ListFormulasLayout.jpg
    ListFormulasLayout.jpg
    19.6 KB · Views: 14
Upvote 0
Solution
Hi there,

Set up a blank sheet with the same layout I have done in the attached image, change the variables I have marked in the following macro to your specific needs and then try the following:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wb As Workbook
    Dim wsDestin As Worksheet, wsSrc As Worksheet
    Dim rngMyCell As Range
    Dim strFindWhat As String, strFormula As String
    Dim lngPasteRow As Long
   
    Application.ScreenUpdating = False
   
    Set wb = ThisWorkbook
    Set wsDestin = wb.Sheets("Sheet1") '<-Name of sheet to put the results. Change to suit if necessary.
    strFindWhat = wsDestin.Range("B1").Value '<-Cell in sheet 'wsDestin' that has the text to search within formulas for. Change to suit if necessary.
   
    If WorksheetFunction.CountA(wsDestin.Cells) > 0 Then
        lngPasteRow = wsDestin.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    Else
        lngPasteRow = 3 '<-Starting row for the output if there's no data in 'wsDestin'. Change to suit if necessary.
    End If
   
    For Each wsSrc In wb.Sheets
        If wsSrc.Name <> wsDestin.Name Then
            For Each rngMyCell In wsSrc.UsedRange
                If rngMyCell.HasFormula = True Then
                    strFormula = rngMyCell.Formula
                    If InStr(strFormula, strFindWhat) > 0 Then
                        wsDestin.Range("A" & lngPasteRow).Value = wb.Name
                        wsDestin.Range("B" & lngPasteRow).Value = wsSrc.Name
                        On Error Resume Next
                            wsDestin.Range("C" & lngPasteRow).Value = rngMyCell.Name.Name
                        On Error GoTo 0
                        wsDestin.Range("D" & lngPasteRow).Value = rngMyCell.Address
                        wsDestin.Range("E" & lngPasteRow).Value = rngMyCell.Value
                        wsDestin.Range("F" & lngPasteRow).Value = "'" & rngMyCell.Formula
                        lngPasteRow = lngPasteRow + 1
                    End If
                End If
            Next rngMyCell
        End If
    Next wsSrc
   
    Application.ScreenUpdating = True
   
    MsgBox "Done", vbInformation

End Sub

Regards,

Robert
Robert! This is wonderful! I'm sorry it took me so long to get back to. Looks like it's working! This is a wonderful Christmas miracle to me. Thank you!!!!
 
Upvote 0
Robert! This is wonderful! I'm sorry it took me so long to get back to. Looks like it's working! This is a wonderful Christmas miracle to me. Thank you!!!!
The only error I'm seeing is that the results seem to skip populating column "C" and are populating in Col "D".
 

Attachments

  • 2021-12-21_9-31-27.png
    2021-12-21_9-31-27.png
    41.4 KB · Views: 6
Upvote 0
Robert! This is wonderful! I'm sorry it took me so long to get back to. Looks like it's working! This is a wonderful Christmas miracle to me. Thank you!!!!

You're welcome (y)

The only error I'm seeing is that the results seem to skip populating column "C" and are populating in Col "D".

I had Col. C to return the name of a named range (if used) of a cell formula as per your original screen shot. This is why my columns go F while yours only go to E causing the alignment issue.

As it seems Col. C is not needed ty this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wb As Workbook
    Dim wsDestin As Worksheet, wsSrc As Worksheet
    Dim rngMyCell As Range
    Dim strFindWhat As String, strFormula As String
    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    Set wb = ThisWorkbook
    Set wsDestin = wb.Sheets("Sheet1") '<-Name of sheet to put the results. Change to suit if necessary.
    strFindWhat = wsDestin.Range("B1").Value '<-Cell in sheet 'wsDestin' that has the text to search within formulas for. Change to suit if necessary.
    
    If WorksheetFunction.CountA(wsDestin.Cells) > 0 Then
        lngPasteRow = wsDestin.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    Else
        lngPasteRow = 3 '<-Starting row for the output if there's no data in 'wsDestin'. Change to suit if necessary.
    End If
    
    For Each wsSrc In wb.Sheets
        If wsSrc.Name <> wsDestin.Name Then
            For Each rngMyCell In wsSrc.UsedRange
                If rngMyCell.HasFormula = True Then
                    strFormula = rngMyCell.Formula
                    If InStr(strFormula, strFindWhat) > 0 Then
                        wsDestin.Range("A" & lngPasteRow).Value = wb.Name
                        wsDestin.Range("B" & lngPasteRow).Value = wsSrc.Name
                        wsDestin.Range("C" & lngPasteRow).Value = rngMyCell.Address
                        wsDestin.Range("D" & lngPasteRow).Value = rngMyCell.Value
                        wsDestin.Range("E" & lngPasteRow).Value = "'" & rngMyCell.Formula
                        lngPasteRow = lngPasteRow + 1
                    End If
                End If
            Next rngMyCell
        End If
    Next wsSrc
    
    Application.ScreenUpdating = True
    
    MsgBox "Done", vbInformation

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,306
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top