vba 对 Array 元素的 MINUS 运算

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13931786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:52:20  来源:igfitidea点击:

MINUS operation on Array elements

excel-vbavbscriptvbaexcel

提问by arun_roy

I have an Array say A=(11,23,32,44,56,88,55,14,78,79) And B=(44,56,88,55,14) .Now using VBScript can I perform Set operation MINUSto get an other output say C=(11,23,32,78,79)?

我有一个数组说 A=(11,23,32,44,56,88,55,14,78,79) 和 B=(44,56,88,55,14) 。现在使用 VBScript 我可以执行 Set操作MINUS以获得其他输出,比如 C=(11,23,32,78,79)?

Array A and B can be considered also two Excel columns.

数组 A 和 B 也可以被认为是两个 Excel 列。

Don't want to use any Looping technique.

不想使用任何循环技术。

Please help

请帮忙

Thanks,

谢谢,

回答by Larry

No, vbs or vba cannot directly do a minus operation on two array ( no build-in function ) You must use loops and here is a good reference for array operations in vba http://www.cpearson.com/excel/vbaarrays.htm

不,vbs 或 vba 不能直接对两个数组进行减号操作(没有内置函数)您必须使用循环,这里是 vba 中数组操作的一个很好的参考http://www.cpearson.com/excel/vbaarrays。 htm

回答by Ekkehard.Horner

Perhaps it's not a surprise that Dictionariesare the VBScript tool to implement (fake?) sets and operations on them. See this Set demo.

字典是实现(假的?)集合和操作的 VBScript 工具,这也许并不奇怪。请参阅此设置演示

BTW: If you have to deal with more than one thingy, you'll have to loop or ask someone else to loop for you. Insisting on "no loop, please" makes no sense. If 'it works', you may optimize by replacing multiple loops (n x m .. x z) by lookup tables or pre-computations, but you won't understand the problem, if you don't think of loopings.

顺便说一句:如果你必须处理不止一件事情,你必须循环或请其他人为你循环。坚持“请不要循环”是没有意义的。如果“它有效”,您可以通过查找表或预计算替换多个循环 (nxm .. xz) 来优化,但如果您不考虑循环,您将无法理解问题所在。

回答by soco

You can do that in Excel vba if u have named ranges AcolBcol

如果你有命名范围,你可以在 Excel vba 中做到这一点 AcolBcol

Range("C3:C10").FormulaArray = "=Acol-Bcol"