gpt4 book ai didi

listbox - Excel VBA : Listbox

转载 作者:行者123 更新时间:2023-12-04 20:20:24 25 4
gpt4 key购买 nike

假设我有一系列值:

Customer | Services | Cost  | Paid
Mel | Abc | $1.00 | TRUE
Mel | Def | $2.00 | FALSE
Xin | Abc | $3.00 | TRUE
Titus | EEE | $4.00 | TRUE

我希望将这些项目插入到列表框中。但是我有一些标准,即仅显示特定于用户的项目(例如 Mel 或 Xin 或 Titus),并且仅在“False”时显示。我该怎么做,提前谢谢。

我现在拥有的:
Dim lbtarget As MSForms.ListBox
Dim rngSource As Range
Set rngSource = Range("Table1")
Set lbtarget = Me.ListBox1
With lbtarget
'Determine number of columns
.ColumnCount = 4
'Set column widths
.ColumnWidths = "50;80;100"
'Insert the range of data supplied
.List = rngSource.Cells.Value
End With

最佳答案

代替

.List = rngSource.Cells.Value


For Each rw In rngSource.Rows
If rw.Cells(1,1) = <Specify User> And rw.Cells(1,4) = FALSE Then
.AddItem ""
For i = 1 To .ColumnCount
.List(.ListCount - 1, i - 1) = rw.Value2(1, i)
Next
End If
Next

Whole Sub 使用 Mel 作为用户
Private Sub CommandButton1_Click()
Dim lbtarget As MSForms.ListBox
Dim rngSource As Range
Dim rw As Range
Dim i As Long

Set rngSource = Range("Table1")
Set lbtarget = Me.ListBox1
With lbtarget
.ColumnCount = 4
.ColumnWidths = "50;80;100"
For Each rw In rngSource.Rows
If rw.Cells(1, 1) = "Mel" And rw.Cells(1, 4) = False Then
.AddItem ""
For i = 1 To .ColumnCount
.List(.ListCount - 1, i - 1) = rw.Cells(1, i)
Next
End If
Next
End With

End Sub

关于listbox - Excel VBA : Listbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5088787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com