- 帖子
- 2
- 主題
- 1
- 精華
- 0
- 積分
- 5
- 點名
- 0
- 作業系統
- window10
- 軟體版本
- office2016 32bit
- 閱讀權限
- 10
- 性別
- 男
- 註冊時間
- 2019-9-16
- 最後登錄
- 2021-3-24
|
[發問] 複製前一個月公式至當月並將前一個月公式貼上為值
本帖最後由 johnny05181983 於 2019-11-2 16:46 編輯
C欄當月數據均由公式統計,跨月時會以人工方式將上月公式複製到下一列當月以利持續統計當月數據,再以人 ...
msmplay 發表於 2017-4-30 13:00 
下面是我參考以前有發文過的資料自己試著改寫,但真的很菜,寫完都沒有反應
請問大家可否指導一下那邊有問題!!
Sub 本月貼上月公式()
Dim xArea As Range, xColumn As Range, M1%, M2%
Set xArea = [B2:M8] '設定範圍
M1 = Month(Date) '取月份
For Each xColumn In xArea.Columns
M2 = Val(xColumn.Cells(1, 0))
If M1 - M2 = 1 Then
If xColumn(2).HasFormula Then Exit Sub
If xColumn.HasFormula Then
xColumn.Copy xColumn(2)
Else
MsgBox xColumn.Cells(1, 0) & "無公式或公式不齊全!! ": Exit Sub '同一列儲存格都有公式才會複製
End If
End If
If M2 < M1 Then xColumn = xColumn.Value
Next
End Sub |
|