为范围 VBA Excel 中的每个单元格设置偏移值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18233206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set an offset value for each cell in a range VBA Excel
提问by SpenceLegend
I am trying to compare a value to each cell in a range. Once there is a match, I want to set another variable to old the value that is offset 3 columns over.
我正在尝试将一个值与范围内的每个单元格进行比较。一旦匹配,我想将另一个变量设置为旧的偏移 3 列的值。
For Each i In Worksheets("SFDC Input").Range("D2:D20").Cells
If ProductFamily = i Then
i.Offset(0, -3).Value = ID
End If
Next
ProductFamily is the value I am comparing to i. I want ID to be the value holder.
ProductFamily 是我与 i 比较的值。我希望 ID 成为价值持有者。
回答by Brian Phillips
It looks as though your assignment (=
) is backwards. You're setting i.Offset(0, -3).Value
to ID
instead of setting ID
to the value.
看起来你的作业 ( =
) 是倒退的。您设置i.Offset(0, -3).Value
为ID
而不是设置ID
为值。
Try the following:
请尝试以下操作:
ID = i.Offset(0, -3).Value
From MSDN:
从MSDN:
The = operator assigns the value on its right to the variable or property on its left.
= 运算符将其右侧的值分配给其左侧的变量或属性。