- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 119
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-5-17
               
|
回復 22# candy516
這樣可能麻煩一點
程式將填入填權日數,並將10日內填權名單列出
請將程式碼置於Sheet1模組- Sub 填權()
- Dim A As Range, Ar()
- Set dic = CreateObject("Scripting.Dictionary")
- Set myday = CreateObject("Scripting.Dictionary")
- ReDim Preserve Ar(z)
- Ar(z) = Array("公司", "年度", "填權日數")
- z = z + 1
- Dim Sh As Worksheet
- For j = Sheets.Count To 1 Step -1
- Set Sh = Sheets(j)
- With Sh
- If .Name <> Me.Name Then
- Set rng = .Range(.[B1], .Cells(1, .Columns.Count).End(xlToLeft))
- If Application.CountBlank(rng) > 0 Then rng.SpecialCells(xlCellTypeBlanks).EntireColumn.Delete
- For r = .Cells(.Rows.Count, 1).End(xlUp).Row To 3 Step -1
- Set A = .Cells(r, 1)
- myday(A.Value) = temp
- temp = A.Value
- Next
- Else
- For Each A In .Range(.[A2], .Cells(.Rows.Count, 1).End(3))
- dic(A & Year(A.Offset(, 1))) = A.Offset(, 1)
- Next
- End If
- End With
- Next
- For Each Sh In Sheets
- With Sh
- If .Name < Me.Name Then
- k = 2: dn = .Name
- Do Until .Cells(1, k) = ""
- .Columns(k + 1).Insert
- f = .Cells(1, k)
- Set A = .Columns("A").Find(dic(f & dn))
- If A Is Nothing Then GoTo 20
- d = myday(A.Value)
- With Sheets(CStr(Year(d)))
- Set b = .Columns("A").Find(d)
- Set c = .Rows(1).Find(f)
- If b Is Nothing Or c Is Nothing Then cnt = "無填權": GoTo 10
- x = b.Row
- y = c.Column
- test = .Cells(x, y)
- End With
- r = A.Row: cnt = 1
- Do Until r = 2 Or .Cells(r, k) >= test
- r = r - 1
- cnt = cnt + 1
- Loop
- If r = 2 Then cnt = "無填權"
- 10
- .Cells(A.Row, k + 1) = cnt
- If IsNumeric(cnt) And cnt <= 10 Then
- ReDim Preserve Ar(z)
- Ar(z) = Array(f, dn, cnt)
- z = z + 1
- End If
-
- 20
- k = k + 2
- Loop
- End If
- End With
- Next
- Set dic = Nothing
- Set myday = Nothing
- With Worksheets.Add
- .[A1].Resize(z, 3) = Application.Transpose(Application.Transpose(Ar))
- .Move
- End With
- End Sub
複製代碼 |
|