vba 选择整行数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7885282/
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
Selecting entire row of data
提问by user1012091
I have a row of data (A3 to A11) that I would like to select (there are no blanks in this range). I am using the following code:
我有一行数据(A3 到 A11)要选择(此范围内没有空格)。我正在使用以下代码:
Range(ws.Range("A3"), ws.Range("A3").End(xlToRight)).Select
However, this code is only selecting cell A3 and not A3 to A11. I have also tried xlToLeft and that still only selects A3 as well...How can I correct this? Thanks.
但是,此代码仅选择单元格 A3 而不是 A3 到 A11。我也试过 xlToLeft 并且仍然只选择 A3 ......我该如何纠正?谢谢。
回答by Nick
Just because of your title, here are a couple ways to select a row
仅仅因为您的标题,这里有几种选择行的方法
ws.Rows(3).Select
ws.Range("a3").EntireRow.Select
to select all the data on a row,
选择一行中的所有数据,
ws.Range("A3",ws.Cells(3,ws.Columns.Count).End(xlToLeft)).Select
Also in your example, you're missing the "ws." prefix from the outermost range object - without specifying the worksheet, Excel will try to refer to the ActiveSheet and you've just written a potential bug.
同样在您的示例中,您缺少“ws”。最外层范围对象的前缀 - 不指定工作表,Excel 将尝试引用 ActiveSheet,而您刚刚编写了一个潜在的错误。
回答by brettdj
I think this overlaps with Populating a list box with data from worksheet. I suggest you continue any issues related to this thread back in the original posting
我认为这与用工作表中的数据填充列表框重叠。我建议您在原始帖子中继续与此线程相关的任何问题
As per prior question to select vertically you use xlDown and xlUp (not xltoRight or xltoLeft)
根据先前的问题垂直选择您使用 xlDown 和 xlUp (不是 xltoRight 或 xltoLeft)
ws.Range(ws.[a3], ws.Cells(Rows.Count, "A").End(xlUp))
回答by Deepak Kushwaha
To select entire row Dynamically(current active cell), Try Below VBA code snippet:
要动态选择整行(当前活动单元格),请尝试以下 VBA 代码片段:
ActiveSheet.Range(Selection, Selection).EntireRow.Select
回答by niko
You need to select range from A3 to A11. This would do the trick
您需要选择从 A3 到 A11 的范围。这可以解决问题
activesheet.range("A3:A11").select or
activesheet.range(cells(3,"A"),cells(11,"A")).select or
activesheet.range(cells(3,1),cells(11,1)).select
回答by Fionnuala
How about:
怎么样:
a = Range("A11").End(xlToRight).Address
Range("A3:" & a).Select
回答by dave
RANGE("A1", Cells(RANGE("A23").row, Columns.Count).End(xlToLeft)).Select 'YES
回答by Nhubs
Try This...
尝试这个...
ActiveSheet.UsedRange.EntireRow.Select
ActiveSheet.UsedRange.EntireRow.Select