Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Need help on Overflow Error '6'



Hi,

I've written a short routine to find the 3-hourly average of
temperature.  This is my first encounter with Excel VBA (or any Visual
Basic for that matter).  I have a similar program that calculates the
average precipitation but instead of 105 stations, there are 25
stations.  Everything else is the same and the precipitation routine
works.  I've tried changing the number of station from 105 and it will
only work if it's all the way down to 4 (FOUR!).  I've also added a
line in there to see if I had divided by zero but that wasn't the
case.  Below is the code:

Sub Hrlyavg()
Dim i As Integer
Dim acc_pcp As Double
Dim count, start_time, num_station, last_entry, output_row,
num_time_interval As Long

'Constants
num_station = 4    'was 105
last_entry = 14612
output_row = 14615
num_time_interval = 8

Cells(output_row, 1).Value = "HR:"

For station = 1 To num_station
    For t = 0 To (num_time_interval - 1)
        start_time = 5
        acc_pcp = 0
        count = 0
        
        'Finds the accumulated total of precip
        For i = (start_time + t) To last_entry Step num_time_interval
            If Cells(i, station + 1).Value > -8888 Then
                acc_pcp = Cells(i, station + 1).Value + acc_pcp
                count = count + 1
            End If
        Next i
    
    'Outputs average
    Cells(output_row + t + 1, station + 1).Value = acc_pcp / count  
'<--this line is highlighted when I press debug
    Cells(output_row + t + 10, station + 1).Value = count
    'Outputs header
    If station = 1 Then
        Cells(output_row + t + 1, station).Value = t * 3
    End If
    
    Next t
Next station

End Sub

I'm using Excel XP. 
A question on the side, how hard is it to have the program graph all
those values and put them on a single chart?

Thanks in advance!



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.