我根本没有太多的 VBA 经验,但这是我想要做的(代码如下):
我有两张纸——一张是模具,一张是销售。每个销售都有一个来自它的骰子,具有多个销售对一个骰子的关系。我想遍历所有模具,并在该循环中遍历所有销售,并在输出它们之前将每一行与一组标准进行比较。
'All dies have a type and a size. All products have a type and a size. We hope to match them.
Sub searchroute()
Dim x As Integer, y As Integer, z As Integer
x = 0 'for row offset on dies, number
y = 0 'for row offset on sales, item
z = 0 'for later use
Do Until IsEmpty(Worksheets("Dies").a2.Offset(x, 0)) = True
Do Until IsEmpty(Worksheets("Sales").a2.Offset(y, 0)) = True
If Worksheets("Dies").i2.Offset(x, 0) = Worksheets("Sales").c2.Offset(y, 0) Or Worksheets("Dies").i2.Offset(x, 0) = "Any" Then
If Worksheets("Sales").g2.Offset(y, 0) = Worksheets("Dies").j2.Offset(x, 0) Or Worksheets("Dies").j2.Offset(x, 0) = "Any" Then
'then we've got the same type and size, print output to a cell
'should figure out how to append, place the whole list in a single cell
End If
End If
y = y + 1
Loop
x = x + 1
Loop
End Sub
逐步执行此操作,它会在第一个“直到”时弹出 438 错误。我知道这很容易,但我的大脑一片空白。
提前感谢您的智慧!