Hi,
I have to calculate the average of each column values at sheet 2 and store it to sheet 3. While I am running the code, it ends with Runtime Error 6 Overflow. My code is given below.
Could you please help me to settle this.. Thanks
I have to calculate the average of each column values at sheet 2 and store it to sheet 3. While I am running the code, it ends with Runtime Error 6 Overflow. My code is given below.
Code:
Sub AvgCal()
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Dim count As Integer
Dim sum As Long
Dim avr As Long
Dim lstCol As Integer
lstCol = ws2.UsedRange.Columns(ws2.UsedRange.Columns.count).Column
For c = 2 To lstCol
sum = 0
count = 0
ws2.Cells(1, c).Select
Do While ActiveCell.Value <> ""
sum = sum + ActiveCell.Value
count = count + 1
ActiveCell.Offset(1, 0).Activate
Loop
ws3.Cells(2, c).Value = sum / count
Next c
End Sub
Could you please help me to settle this.. Thanks
Last edited by a moderator: