VBA:: intersect vs. match method

拜拜、爱过 提交于 2019-12-12 06:59:58

问题


I had a question pertaining to the two built in VBA function of .Match and .Intersect. Currently I have 2 1-dimensional arrays that I wish to consolidate information into a new array. I realize I've posted a question about the approach to the problem earlier but this question pertains to which method would be better. Would one way be able to consolidate information into a new array faster than the other? and is one method more reliable than the other as well?


回答1:


From Excel help

Excel Developer Reference

Application.Intersect Method
Returns a Range object that represents the rectangular intersection of two or more ranges.

Arrays are not ranges, so interset is not applicable to your question as stated.

A more detailed explanation of what you are trying to do, and what form your raw data is in will allow better advice




回答2:


If you are merging your two arrays in vba, then the .Match function and the .Intersect do not behave the same way because, you won't be able to merge with a Match function, you will only be able to find a value.

Hence, i would say, use intersect method.

If you want a more precise answer, please tell us more precisely what you want to do with your arrays with examples and the code you already built.

Regards,

Max




回答3:


Intersect is a method for finding the intersection of one or more ranges: it won't work with arrays. It returns the subset range that is the intersection of the range arguments.
Unless your arrays are sorted it would probably be more efficient to just loop compare the arrays than use .MATCH



来源:https://stackoverflow.com/questions/6503300/vba-intersect-vs-match-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!