返回列表 上一主題 發帖

[發問] Listbox欄位顯示的問題

回復 1# lifedidi
見ColumnCount 說明

若將 ColumnCount 設成 0,顯示的行數便是 0;若設成 -1,便顯示所有的資料行。
對一個非資料連結的資料來源而言,最多只能有 10 行 (0 到 9)。
您可用 ColumnWidths 屬性來設定控制項中的資料行寬。

TOP

回復 3# lifedidi
要破10欄限制,1是從 .RowSource 引用工作表範圍
2是用二維陣列一次給到 .List ,如下
  1. Private Sub UserForm_Initialize()
  2.   Dim ar

  3.   With ListBox1
  4.       .ColumnCount = 37
  5.       .ColumnWidths = "20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt"
  6.   End With
  7.   
  8.   With Sheet5
  9.     ar = .Range(.[a1], .[a1].End(xlDown)).Resize(, 37).Value
  10.   End With
  11.   ListBox1.List = ar

  12. End Sub
複製代碼

TOP

直接用不行嗎?
  1. Private Sub UserForm_Initialize()
  2.   Dim ar

  3.   With Sheet5
  4.     ar = .Range(.[a2], .[a2].End(xlDown)).Resize(, 37).Value
  5.   End With
  6.   With ListBox1
  7.     .ColumnCount = 37
  8.     .ColumnWidths = "20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt;20 pt"
  9.     .List = ar
  10.   End With  
  11. End Sub
複製代碼
回復 5# lifedidi

TOP

回復 8# lifedidi
我要抓取"陳曉明" 則 點第一行 Listbox1.value = 資料庫的值 即可抓到開頭

看不懂,附上檔案程式看看

TOP

回復 10# lifedidi
名字會重複嗎? 不會就改用名字判斷
If Sheet1.Cells(i, 2) = ListBox1.List(ListBox1.ListIndex, 1) Then

TOP

        靜思自在 : 能付出愛心就是福,能消除煩惱就是慧。
返回列表 上一主題