の代わりにそれを置く発見された場合。基本的には同じことです。 For
ループの柔軟性は向上しますが、最適化されません(VLookup
が高速です)。それらは両方ともμs/セルの分数のオーダで動作します。
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