回覆列表
  • 1 # 劉家大少爺0111

    在工作表中插入Activate控制元件複選框,並新增類模組clsChk

    Public WithEvents Chkbox As

    MSForms.CheckBox

    Private Sub Chkbox_Click()

    Dim i&, j&, r&, c&, n&, t#, arr#(1 To 4)

    i = Replace(Chkbox.Name, "CheckBox", "")

    r = Application.RoundUp(i / 4, 0)

    c = (r - 1) * 4

    r = r + 2

    With Sheet1

    t = .Cells(r, 6)

    If t <> 0 Then

    For i = c + 1 To c + 4

    j = j + 1

    If .OLEObjects("CheckBox" & i)

    .Object.Value

    Then

    n = n + 1

    arr(j) = 1

    End If

    Next

    If n > 0 Then

    For j = 1 To 4

    If arr(j) Then arr(j) = t / n

    Next

    Cells(r, 7).Resize(, 4) = arr

    Else

    Cells(r, 7).Resize(, 4) = ""

    End If

    End If

    End With

    End Sub

    工作表程式碼區:

    Dim Chk() As New clsChk

  • 中秋節和大豐收的關聯?
  • 意思解元,會元,狀元,榜眼,探花都是第一嗎?