我嘗試從excel中的每一行讀取單元格,並檢查我的單元格是否包含數組中的值。excell vba數組循環在另一個循環內
Dim products As Variant
products = Array("MS-CHOPMAT-6", "MS-BOARDS-3", "MS-CHOP-LR")
Dim element As Variant
For x = 2 To LastRow
order_quantity = Range("$E$" & x).Value
item_price = Range("$F$" & x).Value
For Each element In products
If InStr(Range("$D$" & x), element) > 0 Then
Range("$H$" & x) = order_quantity * 3
Else: Range("$H$" & x) = "ERROR - " & order_quantity & element
End If
Next element
Next
不幸的是,循環中的「元素」始終是最後一個數組(元素)。在這種情況下「MS-CHOP-LR」。
嗨Shai。如何在此代碼中查找產品的索引? – awariat
@awariat你問的是如何得到'產品'數組的索引?使用「匹配」功能? –
沒有如何找到你給我的這段代碼中的產品索引。哪個位置被檢查過? – awariat