只要把你的代碼在For
環......或使用VLookup
像斯科蒂建議。這基本上是一樣的。 A For
循環更靈活,但優化程度較低(VLookup
更快)。它們都以μs/ cell的分數級數運行。
For Each c In Range("A16:A20")
If c.Value2 = "Current Status:" Then
.Range("V" & NewRow) = c.Offset(0, 1)
Exit For
Else
.Range("V" & NewRow) = "0"
End If
Next
如果使用For
循環,這是比什麼是上面多一點點的代碼,但結構更合理...
'Define a value holder variable where it's scope makes sense
Dim NewValue As String
'... other code here ...
'Default: NewValue = ""
NewValue = ""
For Each c In Range("A16:A20")
If c.Value2 = "Current Status:" Then
NewValue = c.Offset(0, 1)
'Exit For is optional in this case. It matters if
'there are multiple matches... do you want first or last result?
Exit For
End If
Next
'Assign NewValue to cell
.Range("V" & NewRow) = NewValue
非常感謝,它顯示了有多少學習呢:) – FotoDJ