Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
formulaarray
-- Don Guillett SalesAid Software "bhofsetz" wrote in message ... 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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Average (exclude 1 min & 1 max Value) | Excel Discussion (Misc queries) | |||
Exclude Cell from Calculation | Excel Discussion (Misc queries) | |||
How do I exclude a cell from an average calculation when the cell. | Excel Discussion (Misc queries) | |||
calculation to exclude weekends | Excel Worksheet Functions | |||
Exclude cells from calculation? | Excel Programming |