Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Worksheet audit

For auditing purposes i want to be able to view all the formulas in a
selected range. I can use the Tools/Options menu where I do a View Formulas
but this is used for the entire sheet and I'm only interested in a selected
range.

I have also reformatted the range by code using: cell.value = "'" &
cell.formula which works fine, but I cannot seem to revert the process.

Does anybody have an idea to how I can display formulas in a selected range
in a nice way?

Thank you
The Doctor
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Worksheet audit

Hi Dr.Schwartz

You could assign the following macro to a toolbar button.
The button would toggle the display of formulas for the selection.

You should be aware that displaying formulas means that dependent formulas
may report errors or incorrect results. Re-toggling the display rectifies
this. For this reason, the macro intentionally includes an annoyingly
intrusive messagebox.

As written, formula cells in the selection are additionally highlighted by
applying a background color to the cell. When toggling the display to normal
view, the color is removed.from resurrected formula cells. If this will
interfere with an existing background color arrangement, you can comment
(or remove) the indicated macro clause.

'--------------------8-----------------------
Sub ToggleSelectionFormulas()
Dim rng As Range, rng1 As Range
Dim cell As Range
Dim blFormulasToDisplay As Boolean
Dim res As Long
Dim msg As String

msg = "Formlas outside the selection" _
& vbNewLine _
& "may report incorrect results" _
& vbNewLine & "or show errors until you" _
& vbNewLine _
& "re-toggle the formla display!!" _
& vbNewLine & vbNewLine _
& "Despite this, do you wish to contine?"

If Application.CountA(Selection) = 0 Then Exit Sub

Set rng = Selection

On Error Resume Next
Set rng1 = Intersect(rng, _
rng.SpecialCells(xlCellTypeFormulas))
blFormulasToDisplay = Not rng1 Is Nothing
On Error GoTo 0

If blFormulasToDisplay Then
res = MsgBox(prompt:=msg, _
Buttons:=vbYesNo, _
Title:="WARNING")
If Not res = vbYes Then
MsgBox "Formula display aborted!"
Exit Sub
End If
For Each cell In rng1.Cells
With cell
.Formula = "'" & .Formula
With .Interior '<<=== Optionally exclude
.ColorIndex = 36 '<<=== Optionally exclude
End With '<<=== Optionally exclude
End With
Next
Else
For Each cell In Intersect(rng, _
rng.SpecialCells(xlCellTypeConstants, 2))
With cell
If .PrefixCharacter = "'" Then
If Left(.Value, 1) = "=" Then
.Value = .Value
.Interior.Pattern = xlNone
End If
End If
End With
Next

rng.Replace What:="=", _
Replacement:="=", _
LookAt:=xlPart
End If

End Sub
'---------------------8----------------------<<

---
Regards,
Norman



"Dr.Schwartz" wrote in message
...
For auditing purposes i want to be able to view all the formulas in a
selected range. I can use the Tools/Options menu where I do a View
Formulas
but this is used for the entire sheet and I'm only interested in a
selected
range.

I have also reformatted the range by code using: cell.value = "'" &
cell.formula which works fine, but I cannot seem to revert the process.

Does anybody have an idea to how I can display formulas in a selected
range
in a nice way?

Thank you
The Doctor



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Worksheet audit

Thank you Mr. Jones, just what I was looking for!

"Norman Jones" wrote:

Hi Dr.Schwartz

You could assign the following macro to a toolbar button.
The button would toggle the display of formulas for the selection.

You should be aware that displaying formulas means that dependent formulas
may report errors or incorrect results. Re-toggling the display rectifies
this. For this reason, the macro intentionally includes an annoyingly
intrusive messagebox.

As written, formula cells in the selection are additionally highlighted by
applying a background color to the cell. When toggling the display to normal
view, the color is removed.from resurrected formula cells. If this will
interfere with an existing background color arrangement, you can comment
(or remove) the indicated macro clause.

'--------------------8-----------------------
Sub ToggleSelectionFormulas()
Dim rng As Range, rng1 As Range
Dim cell As Range
Dim blFormulasToDisplay As Boolean
Dim res As Long
Dim msg As String

msg = "Formlas outside the selection" _
& vbNewLine _
& "may report incorrect results" _
& vbNewLine & "or show errors until you" _
& vbNewLine _
& "re-toggle the formla display!!" _
& vbNewLine & vbNewLine _
& "Despite this, do you wish to contine?"

If Application.CountA(Selection) = 0 Then Exit Sub

Set rng = Selection

On Error Resume Next
Set rng1 = Intersect(rng, _
rng.SpecialCells(xlCellTypeFormulas))
blFormulasToDisplay = Not rng1 Is Nothing
On Error GoTo 0

If blFormulasToDisplay Then
res = MsgBox(prompt:=msg, _
Buttons:=vbYesNo, _
Title:="WARNING")
If Not res = vbYes Then
MsgBox "Formula display aborted!"
Exit Sub
End If
For Each cell In rng1.Cells
With cell
.Formula = "'" & .Formula
With .Interior '<<=== Optionally exclude
.ColorIndex = 36 '<<=== Optionally exclude
End With '<<=== Optionally exclude
End With
Next
Else
For Each cell In Intersect(rng, _
rng.SpecialCells(xlCellTypeConstants, 2))
With cell
If .PrefixCharacter = "'" Then
If Left(.Value, 1) = "=" Then
.Value = .Value
.Interior.Pattern = xlNone
End If
End If
End With
Next

rng.Replace What:="=", _
Replacement:="=", _
LookAt:=xlPart
End If

End Sub
'---------------------8----------------------<<

---
Regards,
Norman



"Dr.Schwartz" wrote in message
...
For auditing purposes i want to be able to view all the formulas in a
selected range. I can use the Tools/Options menu where I do a View
Formulas
but this is used for the entire sheet and I'm only interested in a
selected
range.

I have also reformatted the range by code using: cell.value = "'" &
cell.formula which works fine, but I cannot seem to revert the process.

Does anybody have an idea to how I can display formulas in a selected
range
in a nice way?

Thank you
The Doctor




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Audit Trail Rich[_8_] Excel Discussion (Misc queries) 4 April 10th 10 08:57 PM
Help with time audit Mike Busch[_2_] Excel Discussion (Misc queries) 0 December 18th 07 03:21 PM
Using Audit Tools with Worksheet Protection STCOL100 Excel Discussion (Misc queries) 1 August 11th 05 10:03 AM
need help have audit and i'm going to get slaughtered unless dont think auditors deserveyourmoney guy Excel Worksheet Functions 4 May 24th 05 12:43 AM
Audit Programme Steved[_3_] Excel Programming 6 September 7th 04 01:58 AM


All times are GMT +1. The time now is 08:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"