Averaging Values With Temporary Replacement

vahnx

Board Regular
Joined
Apr 10, 2011
Messages
188
I'm trying to think of a simple way to convert all values in an excel database temporarily to do a calculation with a conversion for one of the values. ie:

73509764.png

(The last cell is an average of A-E, red is an invalid average because..)

<5 would need to be converted to .0025 and <3 to .0015 but only in the background, not changing the actual visible cells to the end user. In VBA I was thinking if having variables for each column then just placing the coded average into the final column like so:

Code:
For i = 1 to 5 (or length of database)
   If Range("A" & CInt(i)).Value = "<5" Then 
      ColAVar = 0.0025
   ElseIf Range("A" & CInt(i)).Value = "<3" Then 
      ColAVar = 0.0015
   Else
      ColAVar = Range("A" & CInt(i)).Value
   End If

   If Range("B" & CInt(i)).Value = "<5" Then 
      ColBVar = 0.0025
   ElseIf Range("B" & CInt(i)).Value = "<3" Then 
      ColBVar = 0.0015
   Else
      ColBVar = Range("B" & CInt(i)).Value
   End If

  [B]ETC..........[/B]
  End If

  Range("F" & CInt(i)).Value = (ColAVar+ColBVar etc.) / 5
Next i

There's gotta be some better method to do this like a
Code:
Range("F" & CInt(i)).Value = Average(Range("A" & CInt(i) & ":E" & CInt(i)).Replace(<5,0.0025:<3,0.0015))
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If I understand correct what you want, I think this can help you:


<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH><TH>D</TH><TH>E</TH><TH>F</TH><TH>G</TH><TH>H</TH><TH>I</TH><TH>J</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="TEXT-ALIGN: right">434</TD><TD style="TEXT-ALIGN: right">475</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold"><5</TD><TD style="TEXT-ALIGN: right">885</TD><TD style="TEXT-ALIGN: right">542</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold">467,2005</TD><TD style="TEXT-ALIGN: right"></TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">Custom format</TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">"<5"</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: right">324</TD><TD style="TEXT-ALIGN: right">536</TD><TD style="TEXT-ALIGN: right">663</TD><TD style="TEXT-ALIGN: right">132</TD><TD style="TEXT-ALIGN: right">456</TD><TD style="TEXT-ALIGN: right">422,2</TD><TD style="TEXT-ALIGN: right"></TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">Value</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold">0,0025</TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">Rigth bottom/Cells format/Number tab/Custom format/type "<5" in the type box</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: right">635</TD><TD style="TEXT-ALIGN: right">787</TD><TD style="TEXT-ALIGN: right">709</TD><TD style="TEXT-ALIGN: right">112</TD><TD style="TEXT-ALIGN: right">323</TD><TD style="TEXT-ALIGN: right">513,2</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold"></TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold"></TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">4</TD><TD style="TEXT-ALIGN: right">64</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold"><3</TD><TD style="TEXT-ALIGN: right">22</TD><TD style="TEXT-ALIGN: right">222</TD><TD style="TEXT-ALIGN: right">543</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold">170,2003</TD><TD style="TEXT-ALIGN: right"></TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">Custom format</TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">"<3"</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">5</TD><TD style="TEXT-ALIGN: right">958</TD><TD style="TEXT-ALIGN: right">113</TD><TD style="TEXT-ALIGN: right">4477</TD><TD style="TEXT-ALIGN: right">33</TD><TD style="TEXT-ALIGN: right">8532</TD><TD style="TEXT-ALIGN: right">2822,6</TD><TD style="TEXT-ALIGN: right"></TD><TD style="COLOR: #0070c0; FONT-WEIGHT: bold">Value</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0; FONT-WEIGHT: bold">0,0015</TD><TD style="TEXT-ALIGN: right; COLOR: #0070c0"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">6</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">7</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*****</TD><TD>*******</TD><TD style="TEXT-ALIGN: right"></TD></TR></TBODY></TABLE>

<TABLE style="BORDER-BOTTOM: black 2px solid; BORDER-LEFT: black 2px solid; PADDING-BOTTOM: 0.4em; BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 0.4em; PADDING-RIGHT: 0.4em; BORDER-COLLAPSE: collapse; BORDER-TOP: black 2px solid; BORDER-RIGHT: black 2px solid; PADDING-TOP: 0.4em" rules=all cellPadding=2 width="85%"><TBODY><TR><TD style="PADDING-BOTTOM: 6px; PADDING-LEFT: 6px; PADDING-RIGHT: 6px; PADDING-TOP: 6px">Worksheet Formulas<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; TEXT-ALIGN: center; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2 width="100%"><THEAD><TR style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH width=10>Cell</TH><TH style="TEXT-ALIGN: left; PADDING-LEFT: 5px">Formula</TH></TR></THEAD><TBODY><TR><TH style="BACKGROUND-COLOR: #e0e0f0; COLOR: #161120" width=10>F1</TH><TD style="TEXT-ALIGN: left">=AVERAGE(A1:E1)</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Markmzz
 
Upvote 0
This appears to work in testing. But it would quickly spool out of control if you had a lot of these kinds of substitutions.

{=SUM(--(SUBSTITUTE(SUBSTITUTE(A1:E1,"<3",0.0015),"<5",0.0025))) / COUNTA(A1:E1)}

Note the braces, it's an array formula, confirm with Ctrl+Shift+Enter
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top