请问如何把工作表中符合条件的记录填写到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
```
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
- ¥15 DS18B20内部ADC模数转换器
- ¥15 做个有关计算的小程序
- ¥15 MPI读取tif文件无法正常给各进程分配路径
- ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
- ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
- ¥15 setInterval 页面闪烁,怎么解决
- ¥15 如何让企业微信机器人实现消息汇总整合
- ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
- ¥15 如何用Python爬取各高校教师公开的教育和工作经历