返回列表 上一主題 發帖

複製公式

本帖最後由 yen956 於 2014-3-22 15:15 編輯

回復 19# myleoyes
試試看:
  1. Sub 建立日期比對表()
  2.     Dim i As Integer
  3.     Sheets("Sheet1").Activate
  4.    
  5.     '根據 [B3], 填入連續9個月的 結算日期 到 欄Z
  6.     '並填入連續9個月的 年月 到 欄Y, 供 [Y2] Match 年月 用
  7.     '因為某些月份超過1筆, 且同月份須寫在同一列, 故用 MATCH 比對是否同一月份的資料
  8.     '請修改 For i = 1 To 9 之 9, 如果預計要要建立連續 12個月的資料, 則改為 12
  9.     For i = 1 To 9
  10.         Cells(i + 2, 26) = DateSerial(Year([B3]), Month([B3]) + i, 1) - 1
  11.         Cells(i + 2, 25) = Year(Cells(i + 2, 26)) - 1911 & Month(Cells(i + 2, 26))
  12.     Next i
  13. End Sub

  14. Sub Exyen()
  15.     Dim Rng, chkRng As Range
  16.     Dim i, endRow, endRow2, blankRow As Integer
  17.     endRow = [A2000].End(xlUp).Row
  18.     [AH1].Resize(200, 40) = ""
  19.     [Y3].Resize(200, 2) = ""
  20.     建立日期比對表
  21.     endRow2 = [Y200].End(xlUp).Row
  22.    
  23.     Sheets("Sheet1").Activate
  24.     [M3] = 0.0254                 '此列 "借用" M$3是個變數並非固定值
  25.     blankRow = 3
  26.     oldRow = 3
  27.     Application.Calculation = xlManual
  28.    
  29.     For i = 3 To endRow
  30.    
  31.         '若 Cells(2, i + 31)<>"", 則這筆資料己結算過, 換下一筆
  32.         If Cells(2, i + 31) <> "" Then GoTo next1:
  33.         
  34.         '否則將 編號 寫入 Cells(2, i + 31)
  35.         Cells(2, i + 31) = Cells(i, 1)
  36.         
  37.         '將 目前這一筆 欄B 之 年月放入 [Y1], 供 [Y2] Match 比對年月 用
  38.         [Y1] = Year(Cells(i, 2)) - 1911 & Month(Cells(i, 2))
  39.         
  40.         '因為某些月份超過1筆, 且同月份須寫在同一列, 故用 MATCH 比對是否同一月份的資料
  41.         [Y2] = "=MATCH(Y1,Y3:Y200,0)"
  42.         
  43.         blankRow = [Y2] + 2
  44.         If Cells(i, 1) <> 0 Then
  45.             Range(Cells(blankRow, i + 31), Cells(endRow2, i + 31)) = "=ROUND($F$" & i & "*$M$3,2)"
  46.         Else
  47.             Range(Cells(blankRow, i + 31), Cells(i, i + 31)) = "=ROUND($F$" & i & "*$M$3,2)"
  48.         End If
  49.         Cells(1, i + 31) = "=SUM(R3C" & i + 31 & ":R200C" & i + 31 & ")"
  50. next1:
  51.      Next
  52.      Application.Calculation = xlAutomatic
  53. End Sub
複製代碼

TOP

        靜思自在 : 甘願做、歡喜受。
返回列表 上一主題