vba Excel宏为单元格添加值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24972059/
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
Excel Macro adding value to cells
提问by Daniel G. Gabori
I would like to ask for some help regarding Excel macros.
我想寻求有关 Excel 宏的帮助。
I have a column full of data, and I want to create a macro that when i run it, it adds "1" to each cell in that column, instead of having to type "1" in all 300 cells. Any suggestions? Thanks for the help.
我有一列充满数据,我想创建一个宏,当我运行它时,它会向该列中的每个单元格添加“1”,而不必在所有 300 个单元格中键入“1”。有什么建议?谢谢您的帮助。
回答by Gary's Student
To place a "1"in the cells:
要放一个“1”在细胞中:
Sub Place1()
Range("A1:A300").Value = 1
End Sub
To add "1" to the current valuein the cells:
要将“1”添加到单元格中的当前值:
Sub Add1()
For Each r In Range("A1:A300")
r.Value = r.Value + 1
Next r
End Sub