View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
david mcritchie david mcritchie is offline
external usenet poster
 
Posts: 691
Default Need Formula Listing Code Modification

Looks to me like it would not find any formulas in cell A1 and terminate.
But the intent was to use special cells to pick up formulas only.

I think you want instead for Range("A"). to use Cells.

Set FormulaCells = Cells.SpecialCells(xlFormulas, 23)

The specialcells automatically limits you to the used range, and
the formulas limits you to the cells with formulas. The 23 selects
all types of formulas.

As far as changes to width go you would record a macro and
place those results into your macro.

--
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Phil Hageman" wrote in message ...
This code creates a new worksheet in a workbook and lists all formulas contained in the target worksheet. Could someone help

modify this code to do the following:
1. The resulting list contains many rows where there are no formulas - would like to omit the blank (no formula) rows.
2. Make the column width for column B and C be "45" (rather than the existing auto fit).
3. When the data in column B or C exceeds the "45" width, expand row height to fit the text, and wrap text.
4. When the formula in column B references a workbook other than the current workbook, make font red in all cells in that row.

Any help would be much appreciated.
Thanks,
Phil

Sub ListFormulas()
Dim FormulaCells As Range, Cell As Range
Dim FormulaSheet As Worksheet
Dim Row As Integer

'Create a range object for all formula cells
On Error Resume Next
Set FormulaCells = Range("A1").SpecialCells(xlFormulas, 23)

'Exit if no formulas found
If FormulaCells Is Nothing Then
MsgBox "No Formulas, or the sheet is protected."
Exit Sub
End If

'Add a new worksheet
Application.ScreenUpdating = False
Set FormulaSheet = ActiveWorkbook.Worksheets.Add
FormulaSheet.Name = "Formulas in " & FormulaCells.Parent.Name

'Set up the column headings
With FormulaSheet
Range("A1") = "Address"
Range("B1") = "Formula"
Range("C1") = "Value"
Range("A1:C1").Font.Bold = True
End With

'Process each formula
Row = 2
For Each Cell In FormulaCells
Application.StatusBar = Format((Row - 1) / FormulaCells.Count, "0%")
With FormulaSheet
Cells(Row, 1) = Cell.Address(RowAbsolute:=False, ColumnAbsolute:=False)
Cells(Row, 2) = " " & Cell.Formula
Cells(Row, 3) = Cell.Value
Row = Row + 1
End With
Next Cell

'Adjust column widths
FormulaSheet.Columns("A:C").AutoFit
Application.StatusBar = False
End Sub