如何根據條件從數組中選擇一個值並將其寫入單元格中?excel vba - 搜索數組中的值
我有這樣的:
Dim Material As Variant
Dim Material1 As Variant
Material1 = Array("16", "20", "26", "32", "40", "50", "63", "70")
Dim Material2 As Variant
Material2 = Array("12", "16", "22", "28", "34", "42", "58", "65")
Dim Rows as Long
For Rows = 9 to lastrow
If Range("P"&Rows).Value <> 0 then
If Range("W"&Rows).value = Material1 then
Material = Material1
'material can be Material2 also, but I would do the same IF
If Range("Z"&Rows).Value > 2 then
Range ("X"&Rows).value = ' this is where I fail, I want to write here a value from Material1 (looping through position 1, 2, etc...)that does the opposite to my condition, i.e. <2 (this is related with formulas in the sheet)
我也沒有忘記「結束」的國際單項體育聯合會和移動到「下一行」
我明白了。但是,是的,我試圖將一個單元格的內容與整個數組進行比較。如果單元格內容是「Material1」(文本),我希望它在名爲「Material1」的數組內搜索一個值。 –
@ZedA。不知道我明白,你想看看列「W」中的文本是否是「Material1」,然後做什麼?在'Material1'數組中找到什麼值? –
是的,如果列「W」中的文本是「Material1」,我希望它在具有相同名稱的數組中搜索一個值。該值必須滿足我的條件,這與列Z有關。如果列Z <2,我希望它在該數組中搜索一個值,當它寫入列X時,將列Z更改爲<2。確定如果我清楚! –