【发布时间】:2017-03-31 14:17:56
【问题描述】:
我在 VBA 中创建了两个相同维度的数组(下面的部分代码,使用两次来创建 2 个数组),我想使用匹配函数/其他一些函数/循环将匹配值位置存储在一个新的vba 中的数组,如果出现错误(非现有值)任何适当的标志(0)。
例如:Array1(美国、英国、新加坡、中国) Array2(印度、美国、英国、新西兰) Array3(0,2,3,0)
我正在寻找如何到达 array3{}
提前致谢!!
Dim wcountryarray() as variant
ReDim wcountryArrayname(1 To maxima5 * Site_countmax * wacountmax) As Variant
counter = 100
lsitetype = 1
For Country_count = 1 To wacountmax
For within_site = 1 To Site_countmax
counter = counter + 2
For Site_types = lsitetype To maxima5 + lsitetype - 1
wcountryArrayname(Site_types) = WB2.Sheets("Data Input").Cells(Site_types + counter, 2).Value & "|" & _
WB2.Sheets("Data Input").Cells(Site_types + counter, 3).Value & "|" & _
WB2.Sheets("Data Input").Cells(Site_types + counter, 4).Value
Next Site_types
counter = counter + 30 - maxima5 - (maxima5 - 1)
columns_Data = columns_Data - 1
Site_types = Site_types - 1
lsitetype = Site_types + 1
Next within_site
counter = (100 * (Country_count + 1)) - Site_types
Next Country_count
【问题讨论】:
-
不确定我是否完全按照您的示例进行操作,但您可以使用
application.match定位另一个数组中一个数组元素的位置。 -
数组公式可以用来“简化”它。结果会返回到工作表吗?
-
不,结果保留在数组中,并将用于根据位置进一步比较两个不同的数组。我将使用它来比较数组 1 中的 USA 和数组 2 中的 USA 的元素。
-
获取类型不匹配错误 13,我正在尝试解决相同的问题,但我们将不胜感激。