ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¤j¶q«Ø¥ßCOMBOBOX ªí³æ¤è¦¡

¦^´_ 1# lichang
  1.     Dim ar
  2.     '¦³´X­Ó¶ñ´X­Ó
  3.     ar = Array("aiSV4", _
  4.                 "aiSV20", _
  5.                 "aiSV40", _
  6.                 "aiSV80", _
  7.                 "aiSV160")
  8.                     
  9.     'combobox1 to combobox20
  10.     For i = 1 To 20
  11.         Controls("ComboBox" & i).List = ar
  12.     Next
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 6# lichang
¦pªG­n¦@¥Î Click ªºÄ²µo¦æ¬°(´N¬O¦@¥Îclick event)
´N­n¹³ #5¼Ó³o¼Ë , §ï¥Îª«¥óÃþ§O¼Ò²Õ³á~
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 6# lichang
¤U­±¬O¤@²³æ¨Ò¤l
form1.JPG
UserForm1 µ{¦¡½X
  1. Private Temp() As Class1

  2. Private Sub UserForm_Initialize()
  3.     Dim i As Long
  4.     For i = 1 To 4
  5.         ReDim Preserve Temp(i)
  6.         Set Temp(i) = New Class1
  7.         Temp(i).InitialControl Controls("ComboBox" & i)
  8.     Next
  9. End Sub
½Æ»s¥N½X
·s¼Wª«¥óÃþ§O¼Ò²Õ Class1
  1. Public WithEvents ComboBox As MSForms.ComboBox

  2. Private Sub ComboBox_Change()
  3.     MsgBox ComboBox.Value    'change °Ê§@
  4. End Sub

  5. Public Sub InitialControl(ByRef oControl As MSForms.ComboBox)
  6.     Set ComboBox = oControl
  7.     ComboBox.List = Array("test1", "test2", "test3", "test4")
  8. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 10# lichang
¬Ý¤£À´§Aªº·N«ä¡A½Ðªþ¹Ï©ÎÀÉ®×»¡©ú¤@¤U¡AÁÂÁ¡C
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 12# lichang
¤£½T©w¬O¤£¬O§A­nªº : ¨C­ÓComboBox ³£¦³¤@­Ó¹ïÀ³ªºÀx¦s®æ , ¨C¦¸ComboBox¿ï¾Ü§ïÅܮɡA¹ïÀ³ªºÀx¦s®æ­È¤]§ïÅÜ¡C

¦]¬°¨Sµ{¦¡½X§Úª½±µ¥Î 8#ªº¨Ò¤l¨Ó­×§ï
UserForm1 µ{¦¡½X
  1. Private Temp() As Class1

  2. Private Sub UserForm_Initialize()
  3.     Dim i As Long
  4.     For i = 1 To 4
  5.         ReDim Preserve Temp(i)
  6.         Set Temp(i) = New Class1
  7.         Temp(i).InitialControl Controls("ComboBox" & i), ActiveSheet.Cells(1799 + i, "B")
  8.     Next
  9. End Sub
½Æ»s¥N½X
·s¼Wª«¥óÃþ§O¼Ò²Õ Class1
  1. Public WithEvents ComboBox As MSForms.ComboBox
  2. Private linkCell As Range

  3. Private Sub ComboBox_Change()
  4.     linkCell.Value = ComboBox.Value
  5. End Sub

  6. Public Sub InitialControl(ByRef oControl As MSForms.ComboBox, ByRef rngLinkCell As Range)
  7.     Set ComboBox = oControl
  8.     ComboBox.List = Array("test1", "test2", "test3", "test4")
  9.     Set linkCell = rngLinkCell
  10. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 12# lichang
¤£¹L³q±`·|¬O³z¹L¤@­Ó«ö¶s¥hIJµo
¦A¤@¦¸©Ê§âªí³æ¤Wªº¸ê®Æ§ó·s¨ì¤u§@ªí
¦Ó¤£¬O³z¹LCombobox change event
³o¼Ë¤]¤ñ¸û²³æ
  1. Private Sub CommandButton1_Click()
  2.     With ActiveSheet.Range("B1799")
  3.         For i = 1 To 4
  4.             .Cells(i, 1).Value = Controls("ComboBox" & i).Value
  5.         Next
  6.     End With
  7. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

¦^´_ 15# lichang
®Ñ¬O¬Ý±o¤£¦h¡A³Ì¦³¦¬Ã¬ªº¬O
Professional Excel Development 2nd
¦ý³o¥»¤£¬Oµ¹¤Jªùªº¤H¬Ýªº¡A¤J§|«e¤T«ä¡C

³Ì¥D­n¬O±`¼g¡A¹J¨ì°ÝÃD¤Wºôgoogle¡A
­n¾Ç·|¤U¹ïÃöÁä¦r¡A¤K¦¨³£¦³µª®×¡C
¦h¼Æµª®×³£·|³sµ²¨ì³o­Ó½×¾Â©ÎExcelHome(©Ò¥H¤~·|¥[¤J³o½×¾Â)
¤¤¤å§ä¤£¨ì¡A§ï­^¤åÃöÁä¦r¡A¦h¥b°ÝÃD·|¦bStackOverflow±o¨ì¸Ñµª

¼g¦h¤F¡A¹J¹L°ÝÃD´N¦h¡A¸Ñ¨M¹Lªº°ÝÃD¤]´N¦h¤F¡A¦p¦¹¦Ó¤w¡C
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

        ÀR«ä¦Û¦b : ¬°¦Û¤v§äÂǤfªº¤H¥Ã»·¤£·|¶i¨B¡C
ªð¦^¦Cªí ¤W¤@¥DÃD