返回列表 上一主題 發帖

在多個工作表作平均值計算,出現RANGE方法(_worksheet物件)失敗之錯誤

在多個工作表作平均值計算,出現RANGE方法(_worksheet物件)失敗之錯誤

下列程式碼在計算工作表2時運行正常,
但是一跳到工作表3計算平均值時卻會錯誤,
找了很久看不出問題所在,
懇請高手可以解惑,謝謝

    Dim col As Integer, p_today As Single, row As Integer
    For i = 2 To 9                           '在工作表2至工作表9作計算
        col = 3   
        Do While Sheets(i).Cells(1, col) <> ""
            If IsNumeric(Sheets(i).Cells(65536, col + 1).End(xlUp).Value) Then     '如果是數字
                p_today = Sheets(i).Cells(65536, col + 1).End(xlUp).Value                '行號(col+1)  存有每天的資料
            Else
                p_today = 0
            End If
            Sheets(i).Activate
            Sheets(i).Cells(65536, col + 1).End(xlUp).Select
            row = Selection.row()
            avg = Application.Average(Range(Sheets(i).Cells(row - 259, col + 1), Sheets(i).Cells(row, col + 1)))
            Sheets(i).Cells(65536, col).Value = avg            '行號col  放置260天平均值
            col = col + 2
        Loop
    Next

感恩版主
已經可以順利運行了!!:D

TOP

        靜思自在 : 能善用時間的人,必能掌握自己努力的方向。
返回列表 上一主題