Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow Error
Ok, I've tried everything. I can't figure out why this is giving me an overflow error. I've tried every combination I can think of. Changing dim datatypes, forcing datatypes... nothing works. I have the following code: Dim varSum As Integer, varCount As Integer Dim ScoringAve As Double Dim i As Integer For i = 1 To 18 If Me.Controls(ScoreBox(i)).Text < "" Then varSum = varSum + Me.Controls(ScoreBox(i)).Text varCount = varCount + 1 End If Next .Cells(LastRow + 1, 30) = (CLng(varSum) / CLng(varCount)) Every combination gives me Overflow errors. How do I fix this?! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow Error
Dim varSum As Integer, varCount As Integer Dim ScoringAve As Double Dim MyNumber as Variant Dim i As Integer For i = 1 To 18 If Me.Controls(ScoreBox(i)).Text < "" Then MyNumber = Me.Controls(ScoreBox(i)).Text if isnumeric(MyNumber) then varSum = varSum + Val(MyNumber) varCount = varCount + 1 end if End If Next .Cells(LastRow + 1, 30) = (CLng(varSum) / CLng(varCount)) "Bishop" wrote: Ok, I've tried everything. I can't figure out why this is giving me an overflow error. I've tried every combination I can think of. Changing dim datatypes, forcing datatypes... nothing works. I have the following code: Dim varSum As Integer, varCount As Integer Dim ScoringAve As Double Dim i As Integer For i = 1 To 18 If Me.Controls(ScoreBox(i)).Text < "" Then varSum = varSum + Me.Controls(ScoreBox(i)).Text varCount = varCount + 1 End If Next .Cells(LastRow + 1, 30) = (CLng(varSum) / CLng(varCount)) Every combination gives me Overflow errors. How do I fix this?! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow Error
Since it is not a type mismatch error I hope you have numeric values in your text boxes. So changing the type of sum variable should work..as below.. Dim varSum As Variant, intCount As Integer Dim ScoringAve As Double Dim i As Integer For i = 1 To 18 If Isnumeric("0" & Trim(Me.Controls(ScoreBox(i)).Text)) Then varSum = varSum + ("0" & Me.Controls(ScoreBox(i)).Text) intCount = intCount + 1 End If Next If this post helps click Yes --------------- Jacob Skaria "Bishop" wrote: Ok, I've tried everything. I can't figure out why this is giving me an overflow error. I've tried every combination I can think of. Changing dim datatypes, forcing datatypes... nothing works. I have the following code: Dim varSum As Integer, varCount As Integer Dim ScoringAve As Double Dim i As Integer For i = 1 To 18 If Me.Controls(ScoreBox(i)).Text < "" Then varSum = varSum + Me.Controls(ScoreBox(i)).Text varCount = varCount + 1 End If Next .Cells(LastRow + 1, 30) = (CLng(varSum) / CLng(varCount)) Every combination gives me Overflow errors. How do I fix this?! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
overflow error | Excel Programming | |||
Overflow error | Excel Programming | |||
Overflow Error | Excel Programming | |||
Help! Overflow Error 6 | Excel Programming | |||
overflow error | Excel Programming |