Excel VBA从带有隐藏列的af过滤列表复制
试试这个。首先在sheet 1上建立以下数据表
A B C D
a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
创建一个命名区域“Dateset”A2:D6。 在表上放置过滤器并隐藏 B 列,然后过滤表以仅显示第一行。
现在在数据集上测试以下代码:
Sub DataCopy()
Dim r
For Each r In Names("Dateset").RefersToRange.Rows
r.Copy Worksheets(2).Range("a65536").End(xlUp).Offset(1, 0)
Next
End Sub
我得到以下结果:
a1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
没有过滤器,我得到(如预期):
a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
你能帮助我找到一种方法来获取所有数据 - 也从可见行获取?
诗。我也尝试过:
Dim c as Range
For Each c In Range("A2", Range("A6")).Cells
Range(c, c.End(xlToRight)).Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
c.EntireRow.Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
Range(c, c.Offset(0, 5)).Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
Next
但没有成功...... 我已经在 Excel 2007 和 2010 中进行了测试。
Try this. First establish the following datatable on sheet 1
A B C D
a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
Create a named area "Dateset" A2:D6.
Put a filter on the table and hide column B and filter the table to show only the first row.
Now test the following code on the dataset:
Sub DataCopy()
Dim r
For Each r In Names("Dateset").RefersToRange.Rows
r.Copy Worksheets(2).Range("a65536").End(xlUp).Offset(1, 0)
Next
End Sub
I get the following result:
a1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
Without the filter I get (as expected):
a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3
a4 b4 c4 d4
a5 b5 c5 d5
Can you help me with a way to get all the data - also from the visible row?
Ps. I have also tried:
Dim c as Range
For Each c In Range("A2", Range("A6")).Cells
Range(c, c.End(xlToRight)).Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
c.EntireRow.Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
Range(c, c.Offset(0, 5)).Copy Worksheets(2).Range("A65536").End(xlUp).Offset(1, 0)
Next
but with no success...
I have tested in Excel 2007 and 2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这绝对看起来像一个错误。
由于似乎只有第一行有问题,因此您可以逐列复制该行,但按整行复制其余行:
That definitely looks like a bug.
Since it's only the first row that seems to be the problem, you could copy THAT row column by column, but copy the remaining rows by entire row:
这是一个黑暗中的刺探:
基本上,您不应该在这些情况下复制类似的行,即隐藏和过滤的行。
如果您想要更好的答案,您应该准确描述您想要做什么。你的例子和解释令人困惑。无论如何对我来说:)我只是不明白你真正想做什么。
Here is a stab in the dark:
Basically you should not be copying rows like that in those circumstances ie hidden and filtered rows.
If you want a better answer you should describe EXACTLY what you are trying to do. Your examples and explanation are confusing. To me anyway :) I just don't understand what you are really trying to do.