在多個工作表作平均值計算,出現RANGE方法(_worksheet物件)失敗之錯誤
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# tsunamix03
你這程式碼是否在 Sheets(2)工作表物件模組裡!
試試看- Option Explicit
- Sub Ex()
- Dim col As Integer, p_today As Single, R As Integer, i As Integer, avg As Double
- For i = 2 To 9 '在工作表2至工作表9作計算
- col = 3
- With Sheets(i)
- Do While .Cells(1, col) <> ""
- If IsNumeric(.Cells(65536, col + 1).End(xlUp).Value) Then '如果是數字
- p_today = .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
- R = .Cells(65536, col + 1).End(xlUp).Row
- avg = Application.Average(.Range(.Cells(R - 259, col + 1), .Cells(R, col + 1)))
- .Cells(65536, col).Value = avg '行號col 放置260天平均值
- col = col + 2
- Loop
- End With
- Next
- End Sub
複製代碼 |
|
|
|
|
|
|
|