Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Exclude cell from average calculation

I have a worksheet that contains test results in various rows/columns. A
formula at the bottom of the column of data calculates stats on this data e.g:
=average(B2,B5,B8,B11,B13)

Occasionally an individual value is identified as an outlier and must be
excluded from the average calculation. To make this easy I'm thinking about
adding two items to the Cell shortcut menu (the one you get when you
right-click over a cell)- "Exclude cell", and "Include cell".

Currently, to exclude a cell from the average calculation I insert an "x"
before the value. This works, but does not look so good. Can anyone think of
a better way to exclude an individual cell from the calculation without
changing the formula itself? Is there a character other than "x" that would
not be seen, or any other method?

Very grateful for any help...

Cheers,
Dave

Here's the code I'm using behind the shortcut menu:
Const cAppTitle As String = "AppTitle"
Const cExcludeSymbol As String = "x" 'string to add or remove indicating
excluded cell

Private Sub ExcludeResult()
'''Add a "x" to the start of a cell to indicate exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then 'don't run in other workbooks
If TypeName(Selection) = "Range" Then 'don't run if chart etc is selected
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) < cExcludeSymbol And
Left(strTemp, 1) < "=" And Len(strTemp) 0 And IsNumeric(strTemp) Then
'not already excluded, not a formula, not blank, is
numeric
rngR.Formula = cExcludeSymbol & strTemp
rngR.Font.ColorIndex = 15
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

Private Sub IncludeResult()
'''Remove a "x" from the start of a cell to remove exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then
If TypeName(Selection) = "Range" Then
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) = cExcludeSymbol Then
rngR.Formula = Right(strTemp, Len(strTemp) -
Len(cExcludeSymbol))
rngR.Style = "Normal"
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Exclude cell from average calculation

Why not just change the value from a number to text. The value will left
align itself as text so you will know that it is excluded and the formula
will just exclude the value.
--
HTH...

Jim Thomlinson


"Dave Ramage" wrote:

I have a worksheet that contains test results in various rows/columns. A
formula at the bottom of the column of data calculates stats on this data e.g:
=average(B2,B5,B8,B11,B13)

Occasionally an individual value is identified as an outlier and must be
excluded from the average calculation. To make this easy I'm thinking about
adding two items to the Cell shortcut menu (the one you get when you
right-click over a cell)- "Exclude cell", and "Include cell".

Currently, to exclude a cell from the average calculation I insert an "x"
before the value. This works, but does not look so good. Can anyone think of
a better way to exclude an individual cell from the calculation without
changing the formula itself? Is there a character other than "x" that would
not be seen, or any other method?

Very grateful for any help...

Cheers,
Dave

Here's the code I'm using behind the shortcut menu:
Const cAppTitle As String = "AppTitle"
Const cExcludeSymbol As String = "x" 'string to add or remove indicating
excluded cell

Private Sub ExcludeResult()
'''Add a "x" to the start of a cell to indicate exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then 'don't run in other workbooks
If TypeName(Selection) = "Range" Then 'don't run if chart etc is selected
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) < cExcludeSymbol And
Left(strTemp, 1) < "=" And Len(strTemp) 0 And IsNumeric(strTemp) Then
'not already excluded, not a formula, not blank, is
numeric
rngR.Formula = cExcludeSymbol & strTemp
rngR.Font.ColorIndex = 15
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

Private Sub IncludeResult()
'''Remove a "x" from the start of a cell to remove exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then
If TypeName(Selection) = "Range" Then
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) = cExcludeSymbol Then
rngR.Formula = Right(strTemp, Len(strTemp) -
Len(cExcludeSymbol))
rngR.Style = "Normal"
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Exclude cell from average calculation

you could have a helper column with x for cells to exclude and use this
ARRAY formula which must be entered/edited with ctrl+shift+enter instead of
just enter.
=AVERAGE(IF(F1:F3<"x",E1:E3))


--
Don Guillett
SalesAid Software

"Dave Ramage" <Dave
wrote in message
...
I have a worksheet that contains test results in various rows/columns. A
formula at the bottom of the column of data calculates stats on this data

e.g:
=average(B2,B5,B8,B11,B13)

Occasionally an individual value is identified as an outlier and must be
excluded from the average calculation. To make this easy I'm thinking

about
adding two items to the Cell shortcut menu (the one you get when you
right-click over a cell)- "Exclude cell", and "Include cell".

Currently, to exclude a cell from the average calculation I insert an "x"
before the value. This works, but does not look so good. Can anyone think

of
a better way to exclude an individual cell from the calculation without
changing the formula itself? Is there a character other than "x" that

would
not be seen, or any other method?

Very grateful for any help...

Cheers,
Dave

Here's the code I'm using behind the shortcut menu:
Const cAppTitle As String = "AppTitle"
Const cExcludeSymbol As String = "x" 'string to add or remove indicating
excluded cell

Private Sub ExcludeResult()
'''Add a "x" to the start of a cell to indicate exclusion from

calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then 'don't run in other workbooks
If TypeName(Selection) = "Range" Then 'don't run if chart etc is

selected
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) < cExcludeSymbol

And
Left(strTemp, 1) < "=" And Len(strTemp) 0 And IsNumeric(strTemp) Then
'not already excluded, not a formula, not blank, is
numeric
rngR.Formula = cExcludeSymbol & strTemp
rngR.Font.ColorIndex = 15
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude

first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

Private Sub IncludeResult()
'''Remove a "x" from the start of a cell to remove exclusion from

calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then
If TypeName(Selection) = "Range" Then
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) = cExcludeSymbol

Then
rngR.Formula = Right(strTemp, Len(strTemp) -
Len(cExcludeSymbol))
rngR.Style = "Normal"
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude

first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exclude cell from average calculation


Don,
How would you insert an array formula like this one using VBA
code?


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=384912

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Exclude cell from average calculation

Thanks Jim, this works very nicely.

If anyone has the same requirement in the future, here is my final code:
Const cExcludedTextColour As Long = 12632256 'colour for text of excluded
cells , default is 12632256 (light grey)

Private Sub ExcludeResult()
'''Add ' to the start of a cell to indicate exclusion from calculations
' Run from worksheet shortcut menu
Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet Is IncludeExcludeTarget Then 'don't run in other
workbooks/worksheets. IncludeExcludeTarget is the object name of the
worksheet this need to work on.
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If rngR.PrefixCharacter < "'" And Left(strTemp, 1) < "="
And Len(strTemp) 0 And IsNumeric(strTemp) Then
'not already excluded, not a formula, not blank, is
numeric
rngR.Formula = "'" & strTemp
rngR.Font.Color = cExcludedTextColour
rngR.HorizontalAlignment = xlRight 'otherwise text would
align left
End If
Next rngR
Next rngA
End If
End Sub

Private Sub IncludeResult()
'''Remove ' prefix from cell to remove exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet Is IncludeExcludeTarget Then
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
If rngR.PrefixCharacter = "'" And IsNumeric(rngR.Formula) Then
rngR.Formula = rngR.Value 'removes ' prefix from value
rngR.Style = "Normal" 'removes text colour and forced
right alignment
End If
Next rngR
Next rngA
End If
End Sub

Cheers,
Dave

"Jim Thomlinson" wrote:

Why not just change the value from a number to text. The value will left
align itself as text so you will know that it is excluded and the formula
will just exclude the value.
--
HTH...

Jim Thomlinson


"Dave Ramage" wrote:

I have a worksheet that contains test results in various rows/columns. A
formula at the bottom of the column of data calculates stats on this data e.g:
=average(B2,B5,B8,B11,B13)

Occasionally an individual value is identified as an outlier and must be
excluded from the average calculation. To make this easy I'm thinking about
adding two items to the Cell shortcut menu (the one you get when you
right-click over a cell)- "Exclude cell", and "Include cell".

Currently, to exclude a cell from the average calculation I insert an "x"
before the value. This works, but does not look so good. Can anyone think of
a better way to exclude an individual cell from the calculation without
changing the formula itself? Is there a character other than "x" that would
not be seen, or any other method?

Very grateful for any help...

Cheers,
Dave

Here's the code I'm using behind the shortcut menu:
Const cAppTitle As String = "AppTitle"
Const cExcludeSymbol As String = "x" 'string to add or remove indicating
excluded cell

Private Sub ExcludeResult()
'''Add a "x" to the start of a cell to indicate exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then 'don't run in other workbooks
If TypeName(Selection) = "Range" Then 'don't run if chart etc is selected
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) < cExcludeSymbol And
Left(strTemp, 1) < "=" And Len(strTemp) 0 And IsNumeric(strTemp) Then
'not already excluded, not a formula, not blank, is
numeric
rngR.Formula = cExcludeSymbol & strTemp
rngR.Font.ColorIndex = 15
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub

Private Sub IncludeResult()
'''Remove a "x" from the start of a cell to remove exclusion from calculations
' Run from worksheet shortcut menu

Dim rngS As Range, rngA As Range, rngR As Range
Dim strTemp As String

If ActiveSheet.Parent Is ThisWorkbook Then
If TypeName(Selection) = "Range" Then
Set rngS = Selection
For Each rngA In rngS.Areas
For Each rngR In rngA.Cells
strTemp = rngR.Formula
If Left(strTemp, Len(cExcludeSymbol)) = cExcludeSymbol Then
rngR.Formula = Right(strTemp, Len(strTemp) -
Len(cExcludeSymbol))
rngR.Style = "Normal"
End If
Next rngR
Next rngA
Else
MsgBox prompt:="Please select a cell to include or exclude first!",
Buttons:=vbExclamation, Title:=cAppTitle
End If
End If
End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exclude cell from average calculation


Thanks Don.

Is there a way to keep the array formula from converting back to a
regular formula if the user clicks in the cell containing the array
formula?

From my limited experience with array formulas I've noticed that each
time you click in the cell it changes the formula from an array formula
to a regular formula unless you exit the cell by hitting
ctrl+shift+enter.

Basically I'd like my user to be able to click in the cell so that it
will show what range is being affected by the formula, then go on to
another cell or whatever they want to do, without having to hit
ctrl+shift+enter and without the formula changing from an array
formula.

Maybe I'm asking for too much but is this possible?

p.s. I tried protecting the sheet to keep the array formulas from
changing but then the ability to click in the cell and have the
affected range highlighted isn't avaliable.


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=384912

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
Average (exclude 1 min & 1 max Value) Ken Excel Discussion (Misc queries) 2 September 10th 08 01:33 PM
Exclude Cell from Calculation KenCQE Excel Discussion (Misc queries) 2 March 21st 07 11:05 AM
How do I exclude a cell from an average calculation when the cell. Sam Excel Discussion (Misc queries) 1 September 7th 05 05:16 PM
calculation to exclude weekends Need2Know Excel Worksheet Functions 6 July 14th 05 09:01 PM
Exclude cells from calculation? Claude Excel Programming 1 April 20th 04 12:35 PM


All times are GMT +1. The time now is 11:34 PM.

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

About Us

"It's about Microsoft Excel"