返回列表 上一主題 發帖

vba瘦身,感恩

回復 1# sillykin
試試看
  1. Option Explicit
  2. Private Sub CommandButton1_Click()
  3.     With Sheets("工作表3")  '不必Select來Select去
  4.         OptionButton4 = .[J11] = 1
  5.         OptionButton3 = .[I11] = 1
  6.         OptionButton2 = .[H11] = 1
  7.         OptionButton1 = .[G11] = 1
  8.     End With
  9. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# sillykin
同樣的不必Select來Select去,試看看。
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2016-2-14 15:38 編輯

回復 11# sillykin
空白的表單模組程式碼
  1. Option Explicit
  2. Dim xAr(), xClass() As New OP_Class
  3. Private Sub UserForm_Initialize()
  4.      Dim xLeft As Integer, xTop As Integer, i As Integer, Form_Height As Integer, Form_Width As Integer
  5.      Dim OB As Object
  6.      xAr = Array("國防事業", "警察單位", "其他公共行政類", "教育類", "學生", "工、商及服務類", "農林漁牧類", "AAA", "BBBB", "CCCC", "DDDDD", "EEE")
  7.      'xAr 也可以是工作表上單欄或單列的範圍
  8.      ReDim xClass(1 To UBound(xAr) + 1)
  9.      xLeft = 10: xTop = 10
  10.      For i = 1 To UBound(xAr) + 1
  11.         Set OB = Controls.Add("Forms.OptionButton.1", "OptionButton" & i)
  12.         
  13.         Set xClass(i).Op = OB
  14.         With OB
  15.             .Caption = xAr(i - 1)
  16.             .Tag = i
  17.             .Left = xLeft
  18.             .Top = xTop
  19.             .Width = 150
  20.             .Height = 20
  21.             If i Mod 10 Then
  22.                  xTop = xTop + 10 + .Height
  23.                  Form_Height = IIf(Form_Height < xTop, xTop + 10 + .Height * 2, Form_Height)
  24.             Else
  25.                 xTop = 10
  26.                 xLeft = xLeft + 10 * 2 + .Width
  27.                 Form_Width = IIf(Form_Width < xLeft, Form_Width + xLeft + .Width, Form_Width)
  28.             End If
  29.         End With
  30.      Next
  31.      '調整Form的高度,寬度
  32.      Height = Form_Height
  33.      Width = Form_Width
  34. End Sub
複製代碼
物件模組的程式碼
  1. Option Explicit
  2. Public WithEvents Op As MSForms.OptionButton
  3. Private Sub Op_Click()
  4.     'OptionButton
  5.     With Op
  6.         MsgBox .Name & vbLf & .Caption
  7.         [B58] = .Tag
  8.         [C58] = .Caption
  9.         Unload .Parent
  10.     End With
  11.     UserForm40.Show
  12. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題