请问如何把工作表中符合条件的记录填写到VBA listbox中?
7条回答 默认 最新
- 阳光宅男xxb 2023-01-03 14:37关注
Private Sub CommandButton1_Click() ' Purpose: fill listbox with range values after clicking on CommandButton1 ' (code could be applied to UserForm_Initialize(), too) ' Note: based on @Siddharth-Rout 's proposal at https://stackoverflow.com/questions/10763310/how-to-populate-data-from-a-range-multiple-rows-and-columns-to-listbox-with-vb ' but creating a variant data field array directly from range in a one liner ' (instead of filling a redimensioned array with range values in a loop) Dim ws As Worksheet Dim rng As Range Dim MyArray ' variant, receives one based 2-dim data field array '~~> Change your sheetname here Set ws = Sheets("Sheet1") '~~> Set you relevant range here Set rng = ws.Range("A1:C" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row) With Me.ListBox1 .Clear .ColumnHeads = False .ColumnCount = rng.Columns.Count '~~> create a one based 2-dim datafield array MyArray = rng '~~> fill listbox with array values .List = MyArray '~~> Set the widths of the column here. Ex: For 5 Columns '~~> Change as Applicable .ColumnWidths = "50;50;50" .TopIndex = 0 End With End Sub ```bash
```
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
- ¥15 IAR程序莫名变量多重定义
- ¥15 (标签-UDP|关键词-client)
- ¥15 关于库卡officelite无法与虚拟机通讯的问题
- ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
- ¥15 目标检测项目无法读取视频
- ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
- ¥100 求采集电商背景音乐的方法
- ¥15 数学建模竞赛求指导帮助
- ¥15 STM32控制MAX7219问题求解答