excel - 从外部工作表复制一组数据,包括隐藏行
问题描述
所以我想从外部工作表(源)复制一个外部数据集,但源有一个过滤器并且隐藏了一些行。现在我希望的输出是它复制所有数据,包括隐藏的数据。下面是我的代码,其中“ROCV”是内部目标表,“PROJECT DETAIL”是外部数据源:(顺便说一下,我是第一次来这里,也是一个非常业余的 VBA 编码器,所以请多多包涵:D)
Option Explicit
Sub CopyOutput()
Dim wb1 As Workbook, wb2 As Workbook
Dim Ret1, Ret2
Set wb1 = ActiveWorkbook
'~~> Get the File
Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select file")
If Ret1 = False Then Exit Sub
Set wb2 = Workbooks.Open(Ret1, UpdateLinks:=False)
wb2.Sheets("PROJECT DETAIL").Range("a7").CurrentRegion.Copy Destination:=wb1.Worksheets("ROCV").Range("A7")
wb2.Close SaveChanges:=False
Set wb2 = Nothing
Set wb1 = Nothing
End Sub
解决方案
使用ShowAllData
Sub test()
Dim wb1 As Workbook, wb2 As Workbook
Dim Ret1, Ret2
Dim Ws As Worksheet
Dim vDB As Variant
Set wb1 = ActiveWorkbook
'~~> Get the File
Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select file")
If Ret1 = False Then Exit Sub
Set wb2 = Workbooks.Open(Ret1, UpdateLinks:=False)
Set Ws = wb2.Sheets("PROJECT DETAIL")
If Ws.FilterMode Then
Ws.ShowAllData
End If
'** Receives values into a two-dimensional array, and assigns the values of the array back to the target worksheet.
vDB = Ws.Range("a7").CurrentRegion
wb1.Worksheets("ROCV").Range("A7").Resize(UBound(vDB, 1), UBound(vDB, 2)) = vDB
'Ws.Range("a7").CurrentRegion.Copy Destination:=wb1.Worksheets("ROCV").Range("A7")
'wb2.Sheets("PROJECT DETAIL").Range("a7").CurrentRegion.Copy Destination:=wb1.Worksheets("ROCV").Range("A7")
wb2.Close SaveChanges:=False
Set wb2 = Nothing
Set wb1 = Nothing
End Sub
推荐阅读
- angular7 - Formarray 不显示从 service/api 收到的所有记录
- python - 日期时间多索引上的 IndexSlice 不起作用,但似乎与正常工作的玩具等效物没有什么不同
- java - 复杂 RDD 类型到简单数组
- json - 检测没有 JSON 响应的 400 响应
- javascript - 在后台页面中声明的全局函数不会通过 evaluateHandle 调用
- c - 有没有另一种方法来处理这个永远运行的代码?
- php - 如何在 PHP 中分解数组多维
- r - 为什么R会从具有命名行的单列矩阵中提取向量的名称?
- c# - 捆绑破坏了一些样式
- vb.net - 插入的网址无法点击