使用 VBA 从 EXCEL 中的选定行访问单元格的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13859660/
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
Accessing values of cells from selected Rows in EXCEL using VBA
提问by Omkar
I have excel sheet from which I want to update few cell values from Selected rows. How can I do this in VBA? I have not used VBA extensively. Please help.
我有一个 Excel 工作表,我想从中更新选定行中的几个单元格值。我怎样才能在 VBA 中做到这一点?我没有广泛使用 VBA。请帮忙。
Thanks, Omky
谢谢,奥姆奇
回答by Chris Harland
Please see below link. This should be what you are after.
请参阅以下链接。这应该是你所追求的。
http://www.excel-vba-easy.com/vba-programming-range-excel-vba.html
http://www.excel-vba-easy.com/vba-programming-range-excel-vba.html
回答by Tomamais
Omky,
哎呀,
Uyou will need some knowledge of VBA anyway. The Application.Selection variable returns to you the Range currently selected. Try to select an area on your Workbook and execute the macro below:
无论如何,你都需要一些 VBA 知识。Application.Selection 变量返回给您当前选择的范围。尝试在您的工作簿上选择一个区域并执行以下宏:
Sub AreaSelected()
MsgBox Application.Selection.Address
End Sub
And here you have a full example:
这里有一个完整的例子:
http://www.lazerwire.com/2011/10/excel-vba-get-all-selected-rows.html
http://www.lazerwire.com/2011/10/excel-vba-get-all-selected-rows.html
Regards
问候
回答by Patrick Honorez
Sub test()
'put something in column 3 of all selected rows
Dim r As Range
For Each r In Selection.Rows
Cells(r.Row, 3) = "test"
Next r
End Sub