返回列表 上一主題 發帖

[發問] EXCEL 表單內下拉式選單與儲存格連結

本帖最後由 GBKEE 於 2012-8-16 16:17 編輯

回復 4# baiecesi
依你附檔的表單所寫的程式碼 試試看 應是這方面的作法
  1. Dim Ar()
  2. Private Sub UserForm_Initialize()
  3. 'Initialize 事件  發生在一個物件載入後,但尚未顯示的時候。
  4.     ComboBox3.List = Array("Type1", "Type2", "Type3")   'B(總值) 的選項
  5.     'B(總值) 的選項 可指向工作表的位置
  6.     ReDim Ar(UBound(ComboBox3.List))           '重置陣列元素數
  7.     '------因子選項  可指向工作表的位置
  8.     Ar(0) = Array(1.15, 1.25)                  'B(總值) 選項1 的因子選項
  9.     Ar(1) = Array(2.5, 5)                      'B(總值) 選項2 的因子選項
  10.     '------選項3 的因子選項 請自修改
  11.   '  Ar(2) = Array(2.5, 5)                      'B(總值) 選項3 的因子選項
  12.     TextBox1.TabIndex = 1                      '重新設定表單上控制項的 TabIndex 順序
  13.     ComboBox3.TabIndex = 2
  14.     ComboBox1.TabIndex = 3
  15. End Sub

  16. Private Sub ComboBox3_Change()
  17.     ComboBox1.Clear
  18.     Label5.Caption = ""
  19.     If ComboBox3.ListIndex > -1 Then ComboBox1.List = Ar(ComboBox3.ListIndex)
  20.    
  21. End Sub
  22. Private Sub CommandButton1_Click()
  23.     Dim xT(1 To 3) As Double
  24.     If ComboBox3.ListIndex = -1 Or ComboBox3.ListIndex = -1 Then
  25.         Label5.Caption = "ComboBox1.Text * ComboBox3.Text"
  26.     Else
  27.         Select Case ComboBox3.ListIndex       '
  28.             Case 0                            'Type1
  29.                 xT(1) = 7.58
  30.                 xT(2) = 0.8
  31.             Case 1                            'Type2
  32.                 xT(1) = 7.9661
  33.                 xT(2) = 0.8
  34.             Case 2                            'Type3
  35.                 xT(1) = 8.1238
  36.                 xT(2) = 0.7243
  37.         End Select
  38.         xT(3) = Application.Evaluate("Exp(" & xT(1) & "+" & xT(2) & "* Ln(" & Val(TextBox1) & "))") / 1000
  39.         Label5.Caption = Round((550 / 500) * xT(3) * Val(ComboBox1), 2)
  40.     End If
  41. End Sub
  42. Private Sub CommandButton2_Click()
  43.     End
  44. End Sub
複製代碼

TOP

        靜思自在 : 忘功不忘過,忘怨不忘恩。
返回列表 上一主題