Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I have 10 textboxes that will contain values from 1-5. Not all the textboxes HAVE to contain a value, though. How do I write code that will consider all 10 textboxes and give me the average of only the textboxes with values in them? For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The average should show 4. But the next time boxes 1,3,5,7,9 have values 2,4,5,3,5 respectively. The average should show 3.8. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() If the textboxes are named TextBox1, TextBox2 etc;... try something like the below Dim varSum As Long, varCount As Long For intTemp = 1 To 10 If Trim(Me.Controls("Textbox" & intTemp)) < "" Then varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp)) varCount = varCount + 1 End If Next MsgBox "Average :" & (varSum / varCount) If this post helps click Yes --------------- Jacob Skaria "Bishop" wrote: I have 10 textboxes that will contain values from 1-5. Not all the textboxes HAVE to contain a value, though. How do I write code that will consider all 10 textboxes and give me the average of only the textboxes with values in them? For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The average should show 4. But the next time boxes 1,3,5,7,9 have values 2,4,5,3,5 respectively. The average should show 3.8. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() For the text box controls for which you need to sum set the tag property to somthing say "x". Right click on each text box to be consideredFrom properties windows in Tag type 'x'. Then use the below code Dim varSum As Long, varCount As Long Dim objTemp As Object For Each objTemp In Me.Controls If objTemp.Tag = "X" Then If Trim(objtemp.Text) < "" Then varSum = varSum + ("0" & Trim(objtemp.Text)) varCount = varCount + 1 End If End If Next Set objTemp = Nothing MsgBox "Average :" & (varSum / varCount) If this post helps click Yes --------------- Jacob Skaria "Bishop" wrote: I have 10 textboxes that will contain values from 1-5. Not all the textboxes HAVE to contain a value, though. How do I write code that will consider all 10 textboxes and give me the average of only the textboxes with values in them? For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The average should show 4. But the next time boxes 1,3,5,7,9 have values 2,4,5,3,5 respectively. The average should show 3.8. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Finally! I didn't use the tag property but using .Text instead of .Value did the trick. Thank you! "Jacob Skaria" wrote: For the text box controls for which you need to sum set the tag property to somthing say "x". Right click on each text box to be consideredFrom properties windows in Tag type 'x'. Then use the below code Dim varSum As Long, varCount As Long Dim objTemp As Object For Each objTemp In Me.Controls If objTemp.Tag = "X" Then If Trim(objtemp.Text) < "" Then varSum = varSum + ("0" & Trim(objtemp.Text)) varCount = varCount + 1 End If End If Next Set objTemp = Nothing MsgBox "Average :" & (varSum / varCount) If this post helps click Yes --------------- Jacob Skaria "Bishop" wrote: I have 10 textboxes that will contain values from 1-5. Not all the textboxes HAVE to contain a value, though. How do I write code that will consider all 10 textboxes and give me the average of only the textboxes with values in them? For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The average should show 4. But the next time boxes 1,3,5,7,9 have values 2,4,5,3,5 respectively. The average should show 3.8. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Computing the item age | Excel Worksheet Functions | |||
Computing Time from One Day to Another | Excel Discussion (Misc queries) | |||
COMPUTING TWO COLUMNS | Excel Worksheet Functions | |||
"Drop the lowest" in computing average | Excel Worksheet Functions | |||
eliminating #value when computing average | Excel Programming |