返回列表 上一主題 發帖

[發問] 用勾選讓儲存格不能等於

本帖最後由 Hsieh 於 2014-2-10 14:56 編輯

回復 4# j88141
課表雛形工作表模組
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Count > 1 Then Exit Sub
  3. Application.EnableEvents = False
  4. k = Target.Column
  5. r = Target.Row
  6. w = Cells(2, k)
  7. t = IIf(r <= 22, "早上", IIf(r > 22 And r <= 38, "下午", "晚上"))
  8. If Target<>"" And Check(w & t, Target) > 0 Then MsgBox "該教師此時段不排課": Target.ClearContents
  9. Application.EnableEvents = True
  10. End Sub
  11. Function Check(mystr$, MyVal)
  12. Dim Ob As Shape, A As Range, Dic As Object
  13. Set Dic = CreateObject("Scripting.Dictionary")
  14. With 工作表1
  15. For Each Ob In .Shapes
  16.    If Ob.OLEFormat.Object.Value = 1 Then
  17.       Set A = Ob.TopLeftCell
  18.       w = .Cells(1, A.Column).MergeArea(1)
  19.       t = .Cells(3, A.Column)
  20.       Dic(w & t) = IIf(Dic(w & t) = "", .Cells(A.Row, 1), Dic(w & t) & "," & .Cells(A.Row, 1))
  21.    End If
  22. Next
  23. Check = InStr(Dic(mystr), MyVal)
  24. End With
  25. End Function
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 唯其尊重自己的人,才更勇於縮小自己。
返回列表 上一主題