如何将 If 条件传递给 Excel VBA 文本连接?
如何将 Textjoin 中的 if 条件传递到 VBA 等效项中? IE。我当前在 Excel 中的工作公式是:
=TEXTJOIN("",TRUE,IF(M1:M100=1,N1:N100,""))
如果在 M 列中设置了标志,则这是连接 N 列中的行。
我想要得到的是在 VBA 中复制此内容,例如:
abc = WorksheetFunction.TextJoin(" ", True, IF(Range(M1:M100)=1,Range(N1:N100),"")
但似乎无法弄清楚如何将条件传递给工作表函数。 有什么想法吗?
我想这个问题也与 WorksheetFunction.Filter 有关,关于如何向其传递过滤条件,例如:
WorksheetFunction.Filter(Range("M:M"), Range("N:N") & "=1", False)
我这么说就好像我可以计算出过滤器一样,我可能可以直接将该范围传递给文本连接。
谢谢!
How does one pass an if condition in Textjoin into the VBA equivalent?
ie. my working formula in Excel currently is:
=TEXTJOIN("",TRUE,IF(M1:M100=1,N1:N100,""))
This is to join rows in column N if the flag is set in column M.
What I am trying to get is to replicate this in VBA, something like:
abc = WorksheetFunction.TextJoin(" ", True, IF(Range(M1:M100)=1,Range(N1:N100),"")
But can't seem to work out how to pass the criteria to the worksheet function.
Any ideas?
I guess the question also relates to WorksheetFunction.Filter, on how you can pass a filter condition to it, something like:
WorksheetFunction.Filter(Range("M:M"), Range("N:N") & "=1", False)
I say this as if I can work out the filter, I can probably just pass that range to the text join directly.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TEXTJOIN
在 VBA 中使用 If 条件数组If
语句,第二个参数变得无关紧要。您已选择True
来跳过空白,但它们不会被跳过。您可以使用另一个(嵌套)If
语句来覆盖它。Evaluate
方法,而第三个则使用下面的函数。TEXTJOIN
With an If Conditioned Array in VBAIf
statement, the second argument has become irrelevant. You have chosenTrue
to skip blanks but they won't be skipped. You can cover for it with another (nested)If
statement.Evaluate
method, while the third uses the function below.