vba 公式R1C1在excel vba中插入连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21010764/
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
formulaR1C1 insert concatenate string in excel vba
提问by dwstein
I'm trying to insert a concatenated string into a cell using VBA. Here's the formula I want to insert:
我正在尝试使用 VBA 将连接的字符串插入到单元格中。这是我要插入的公式:
="ObjectID(" & E152 & ")"
here's what I'm trying, but I can't get it to work:
这是我正在尝试的,但我无法让它工作:
ActiveCell.FormulaR1C1 = "=""ObjectID("" & RC[-1] & ")"
I've tried "")"
and ")""
and a bunch of other combinations, but I cant get it to work.
我已经尝试过"")"
和")""
一堆其他组合,但我无法让它工作。
How do I do this?
我该怎么做呢?
采纳答案by dwstein
here's how I did it:
这是我如何做到的:
ActiveCell.FormulaR1C1 = "=""ObjectID("" & RC[-1] & "")"""
回答by Jerome Montino
Try this:
尝试这个:
Sub InputConcatenatedString()
FormulaStr = """ObjectID(""&E2&"")"""
Range("A2").Formula = "=" & FormulaStr '--Modify A2 as needed.
Range("A2:A162").FillDown '--Modify affected range as needed.
End Sub
You just have to change the address of the initial cell as well as the end cell in the desired range. I just assumed that your data starts at A2
and ends at A162
. :)
您只需要在所需范围内更改初始单元格的地址以及结束单元格的地址。我只是假设您的数据开始A2
并结束于A162
. :)
Let us know if this helps.
如果这有帮助,请告诉我们。
回答by L42
try this:
尝试这个:
Range("A2:A162").Formula = "=""ObjectID("" & E2 & "")"""
Assuming you want to put your values in A2:A162
.
Change to whatever range you got.
假设你想把你的价值观放在A2:A162
.
更改为您获得的任何范围。