Good afternoon!
I have a macro that pulls all the formulas in a workbook and pastes them into a separate worksheet. I'm running a macro on that worksheet to get a materials pick list.
The macro to pull all the formulas is something I found on the web and it works great except for the fact that it doesn't include the = at the beginning of the formula. I'm a long way from a VBA expert (A Really long way!) and I am not sure just how to modify this macro to show the = in the formulas. I'm hoping someone can tell me what I have to change to do this. I'm guessing it is in the statement
.Offset(1, 0).Value = Mid(c.Formula, 2, (Len(c.Formula)))
in the macro. I would appreciate any input or suggestions.
Thanks much
Bill
Macro attached
Option Explicit
Sub ListAllFormulas()
Dim sht As Worksheet
Dim shtName
Dim myRng As Range
Dim newRng As Range
Dim c As Range
ReTry:
shtName = Application.InputBox("Choose a name for the new sheet to list all formulas.", "New Sheet Name") 'the user decides the new sheet name
If shtName = False Then Exit Sub 'exit if user clicks Cancel
On Error Resume Next
Set sht = Sheets(shtName) 'check if the sheet exists
If Not sht Is Nothing Then 'if so, send message and return to input box
MsgBox "This sheet already exists"
Err.Clear 'clear error
Set sht = Nothing 'reset sht for next test
GoTo ReTry 'loop to input box
End If
Worksheets.Add.Move after:=Worksheets(Worksheets.Count) 'adds a new sheet at the end
Application.ScreenUpdating = False
With ActiveSheet 'the new sheet is automatically the activesheet
.Range("A1").Value = "Formula" 'puts a heading in cell A1
.Range("B1").Value = "Sheet Name" 'puts a heading in cell B1
.Range("C1").Value = "Cell Address" 'puts a heading in cell C1
.Name = shtName 'names the new sheet from InputBox
End With
For Each sht In ActiveWorkbook.Worksheets 'loop through the sheets in the workbook
If sht.Name <> shtName Then 'exclude the sheet just created
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) 'use SpecialCells to reduce looping further
For Each c In newRng 'loop through the SpecialCells only
Sheets(shtName).Range("A65536").End(xlUp).Offset(1, 0).Value = Mid(c.Formula, 2, (Len(c.Formula)))
'places the formula minus the '=' sign in column A
Sheets(shtName).Range("B65536").End(xlUp).Offset(1, 0).Value = sht.Name
'places the sheet name containing the formula in column B
Sheets(shtName).Range("C65536").End(xlUp).Offset(1, 0).Value = Application.WorksheetFunction.Substitute(c.Address, "$", "")
'places the cell address, minus the "$" signs, containing the formula in column C
Next c
End If
Next sht
Sheets(shtName).Activate 'make the new sheet the activesheet
ActiveSheet.Columns("A:C").AutoFit 'autofit the data
Application.ScreenUpdating = True
End Sub
Bookmarks