vba listbox ColumnHeads的表頭
- 帖子
- 8
- 主題
- 3
- 精華
- 0
- 積分
- 11
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office2010
- 閱讀權限
- 10
- 註冊時間
- 2016-5-24
- 最後登錄
- 2016-7-9
|
vba listbox ColumnHeads的表頭
嗨,大家晚安 :
想請教一下VBA表單裡的listbox,切割好欄位後,怎麼新增表頭的文字上去,如下圖,
Google一些文章,都沒有看到合適的,特來請教大家,謝謝
___
|
|
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2016-6-2 07:57
| 只看該作者
回復 1# owenchen0911
listbox,切割好欄位後???
ListBox 要顯示ColumnHeads,清單的來源必需用.RowSource 指定
RowSource 需是單一的連續儲存格範圍 ,不可用切割 |
|
|
|
|
|
|
- 帖子
- 8
- 主題
- 3
- 精華
- 0
- 積分
- 11
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office2010
- 閱讀權限
- 10
- 註冊時間
- 2016-5-24
- 最後登錄
- 2016-7-9
|
3#
發表於 2016-6-2 10:12
| 只看該作者
回復 owenchen0911
listbox,切割好欄位後???
ListBox 要顯示ColumnHeads,清單的來源必需用.RowSour ...
GBKEE 發表於 2016-6-2 07:57 
Hi,
我的code如下,這樣子子項目可以加進去,那麼頭還可以用 "ColumnHeads"嗎??謝謝- ListBox1.ColumnCount = 7
- ListBox1.ColumnHeads = True
- '增加項目進去
- IListRow = ListBox1.ListCount
- ListBox1.AddItem ComboBox_drink_name
-
- ListBox1.List(IListRow, 1) = priceArray(ComboBox_drink_name.ListIndex)
- ListBox1.List(IListRow, 2) = ComboBox_number
- ListBox1.List(IListRow, 3) = ComboBox_number * priceArray(ComboBox_drink_name.ListIndex)
- ListBox1.List(IListRow, 4) = ComboBox_ice
- ListBox1.List(IListRow, 5) = ComboBox_sugar
- ListBox1.List(IListRow, 6) = ComboBox_takeout
-
- xItemCount = xItemCount + 1
複製代碼 |
|
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
4#
發表於 2016-6-3 05:54
| 只看該作者
回復 3# owenchen0911
試試看- Option Explicit
- Dim Sh As Worksheet
- Private Sub UserForm_Initialize()
- Dim Rng As Range
- Set Sh = ActiveSheet '指定ListBox1.RowSource 的工作表
- Set Rng = Sh.Range("A1").CurrentRegion
-
- 'CurrentRegion 屬性 傳回 Range 物件,該物件代表目前的區域。目前區域是指以任意空白列及空白欄的組合為邊界的範圍。
-
- Set Rng = Application.Intersect(Rng, Rng.Offset(1))
- If Rng Is Nothing Then Set Rng = Sh.Range("A1").CurrentRegion.Rows(2) '沒有購物清單
- With ListBox1
- .ColumnHeads = True
- .RowSource = Rng.Address
- End With
- End Sub
- Private Sub Ex_清單() '加入購物清單的程式
- Dim Rng As Range
- Set Rng = Sh.Range("A1").CurrentRegion
- With Rng.Cells(Rng.Rows.Count + 1, "A")
- '增加項目進去
- .Cells(1, 1) = priceArray(ComboBox_drink_name.ListIndex)
- .Cells(1, 2) = ComboBox_number
- .Cells(1, 3) = ComboBox_number * priceArray(ComboBox_drink_name.ListIndex)
- .Cells(1, 4) = ComboBox_ice
- .Cells(1, 5) = ComboBox_sugar
- .Cells(1, 6) = ComboBox_takeout
- End With
- Set Rng = Sh.Range("A1").CurrentRegion
- Set Rng = Application.Intersect(Rng, Rng.Offset(1))
- '重新指定 ListBox1清單範圍
- ListBox1.RowSource = Rng.Address
- End Sub
- Private Sub Ex_清空() '清空 購物清單的程式
- Sh.Range("A1").CurrentRegion.Offset(1).Clear
- End Sub
複製代碼 |
|
|
|
|
|
|