我最近开始使用VBA。我在一个sheet1中创建了一组数据,在表3中我创建了依赖数据变量,尽管我可以从我的数据表中创建一个表。我已经返回以下代码来选择列号,但是我的for循环在15次迭代之后不起作用,其中finalcol指的是我应该从中提取数据的列
Sub collatedlist()
Dim i, j, k, l, m, n As Integer
Dim market(1 To 100, 1 To 100), comparison(1 To 100, 1 To 100)
Dim rowcom, columncom, rowmar, columnmar As Integer
rowcom = Cells(Rows.Count, "B").End(xlUp).Row
columncom = Cells(3, Columns.Count).End(xlToLeft).Column
rowmar = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
columnmar = Sheet1.Cells(3, Columns.Count).End(xlToLeft).Column
Dim finalcol(1 To 5)
For i = 1 To rowcom
For j = 1 To columncom
comparison(i, j) = Cells(i, j).Value
Next j
Next i
For i = 1 To rowmar
For j = 1 To columnmar
market(i, j) = Sheet1.Cells(i, j).Value
Next j
Next i
For i = 3 To columncom
For j = 3 To columnmar
If comparison(3, i) = market(3, j) Then
For k = j To columnmar
If comparison(4, i) = market(4, k) Then
For m = k To 37
If comparison(5, i) = market(5, m) And comparison(4, i) = market(4, m) And comparison(3, i) = market(3, m) Then
finalcol(i) = m
End If
Next m
End If
Next k
End If
Next j
Next i