返回列表 上一主題 發帖

[發問] 關於UserForm1中的ListBox應用

回復 1# av8d
參考看看
UserForm 的程式碼
  1. Dim Sh As Worksheet
  2. Private Sub UserForm_Initialize()
  3.     Set Sh = ActiveSheet
  4.     ListBox1_內容制定
  5. End Sub
  6. Private Sub ListBox1_Click()
  7.     With ListBox1
  8.         If .ListIndex = -1 Then Exit Sub
  9.        Sh.Range(.List(.ListIndex, 1)).Select
  10.       Selection = .List(.ListIndex, 0) & "  " & .List(.ListIndex, 1)  '驗證 項目與位置
  11.     End With
  12. End Sub
  13. Private Sub ListBox1_內容制定()
  14.     Dim Ar(), R As Integer, i As Integer, ii As Integer
  15.     Ar = Array("A", "F", "K", "P")            '指定攔位
  16.     R = 0
  17.     With ListBox1
  18.         .ColumnCount = 2   ' 顯示2個欄位
  19.         .Font.Size = 14
  20.         For i = 0 To 49 Step 4
  21.             R = IIf(i > 3, R + 1, 0)                 '間隔14列的計數
  22.             For ii = 0 To 3
  23.              If i + ii + 1 > 50 Then Exit For
  24.                 .AddItem
  25.                 .List(i + ii, 0) = "項" & i + ii + 1
  26.                 .List(i + ii, 1) = Ar(ii) & IIf(R = 0, 1, R * 13 + R)   '間隔14列的位置
  27.             Next
  28.     Next
  29. End With
  30. End Sub
複製代碼

TOP

        靜思自在 : 不要隨心所欲,要隨心教育自己。
返回列表 上一主題