|
- Sub loadchkbox()
- Dim ChkBox As Control
- Dim i As Integer
- Dim row As Integer
- Dim j As String
- 'Dim x As Range
- Dim maxLen(2) As Integer
- 'Set x = ActiveSheet.Range("1:5").Find(DateValue(Me.录入日期.Caption), lookat:=xlWhole)
- With Worksheets("sheet1")
- row = .Range("A65535").End(xlUp).row
- For i = 2 To row
- If LenB(StrConv(.Cells(i, 2), vbFromUnicode)) > maxLen((i - 2) Mod 3) Then
- maxLen((i - 2) Mod 3) = LenB(StrConv(.Cells(i, 2), vbFromUnicode))
- End If
- Next
- For i = 2 To row
- j = .Cells(i, 1) & " " & .Cells(i, 2) & Space(maxLen((i - 2) Mod 3) - LenB(StrConv(.Cells(i, 2), vbFromUnicode))) & " " & .Cells(i, 3)
- Set ChkBox = UserForm1.Controls.Add("Forms.CheckBox.1", Name:="复选框" & Str(i))
- ' If i Mod 3 = 2 Then
- ChkBox.Top = 30 * Int((i - 2) \ 3)
- ChkBox.Height = 25
- ChkBox.Width = 300
- ChkBox.Caption = j
- ChkBox.Left = 5 + 215 * ((i - 2) Mod 3)
- ' ElseIf i Mod 3 = 0 Then
- ' ChkBox.Top = 10 * Int(i - 3)
- ' ChkBox.Height = 25
- ' ChkBox.Width = 300
- ' ChkBox.Caption = j
- ' ChkBox.Left = 220
- ' Else
- ' ChkBox.Top = 10 * Int(i - 4)
- ' ChkBox.Height = 25
- ' ChkBox.Width = 300
- ' ChkBox.Caption = j
- ' ChkBox.Left = 435
- ' End If
- ' k = i + 1
- Next
- End With
- 'Set ChkBox = Nothing
- End Sub
- Sub loadwin()
- UserForm1.Show
- End Sub
复制代码 完整的简化后的代码,注意:简化只是减少代码的行数,不等于速度上的优化
|
|