vba - 是否有一种方法可以根据列表框列之一的条件在列表框中查找值?
问题描述
我有一个列表框,共有 5 列,第 2 列中有电子邮件地址。我有一些代码循环遍历该列并将电子邮件地址添加到电子邮件中的收件人。它工作得很好,但现在我只需要在列表框第 5 列中添加包含特定值的电子邮件地址。
我已经搜索了查找方法,但找不到列表框的任何内容。
这是没有任何查找条件的代码:
strEmailRecipients = ""
For N = 0 To Me.lstContacts.ListCount - 1
strEmailRecipients = strEmailRecipients & "; " & Me.lstContacts.Column(2, N)
Next N
有什么方法可以修改代码以仅添加第 2 列中满足第 5 列中特定条件的值?
解决方案
我不明白这个问题(也许我错过了一些东西)。
只需使用与已有的相同方法读取列值,使用If
.
strEmailRecipients = ""
For N = 0 To Me.lstContacts.ListCount - 1
If Me.lstContacts.Column(5, N) = "a certain value" Then
strEmailRecipients = strEmailRecipients & "; " & Me.lstContacts.Column(2, N)
End If
Next N
推荐阅读
- excel-formula - 如何在Excel中将ID号与特定月份和年份的总出现次数相加
- variables - 如何:使用 sampleresults 将 JMeterVariable 值保存到 influxdb
- crystal-reports - 在水晶报表中连接字符串
- python - 如何在不丢失元组属性的情况下将元组元素转换为字符串?
- python - 合并两个熊猫系列?
- sas - 将迭代器作为值传递给宏函数
- elixir - 使用 Ecto 从另一个表中预加载 order_by
- java - Spring Security 使用 java.lang.String 来传输用户密码。这不是安全漏洞吗?
- entity-framework - 实体框架核心抛出 DbUpdateConcurrencyException
- pandas - 使用 .loc 和布尔值的多维键的 Pandas 错误