[英]found 'TargetTable.Range.SpecialCells(xlCellTypeVisible).Copy _ ' Destination:=Sheets(“Sheet8”).Range(“A1”)
I have a sheet named "Staffdb" with two named tables "PermTBL" and "StaffTBL", same headers "Girls" "ID" "Hire_date" and "Status". 我有一个名为“ Staffdb”的工作表,其中包含两个命名表“ PermTBL”和“ StaffTBL”,相同的标题为“ Girls”,“ ID”,“ Hire_date”和“ Status”。 All of the current and historic staff are in PermTBL.
目前和历史上所有的员工都在PermTBL中。 I would like to filter PermTBL on the Status field for "A" meaning active and then copy these to the StaffTBL which is empty.
我想在“状态”字段中将PermTBL过滤为“ A”,表示活动,然后将其复制到为空的StaffTBL。 After manually filtering the PermTBL with the Status down arrow and select only "A" I go in to test the code and get an apparent partial copy.
在使用“状态”向下箭头手动过滤PermTBL之后,仅选择“ A”后,我进入测试代码并获得明显的部分副本。 My code is Option Explicit
我的代码是Option Explicit
Sub PermTBLtoStaffTBL() 子PermTBLtoStaffTBL()
Dim rgnsrc As Range Dim rgndest As Range Dim rgnsrc作为范围Dim rgndest作为范围
Set rgnsrc = Worksheets("Staffdb").Range("PermTBL")
Set rgndest = Worksheets("Staffdb").Range("StaffTBL")
rgnsrc.SpecialCells(xlCellTypeVisible).Copy rgndest
End Sub 结束子
Finally as an additional piece of information the StaffTBL appears to have hidden rows, 3-7 are not visible which appears to correspond with my missing data. 最后,作为补充信息,StaffTBL似乎具有隐藏的行,看不见3-7,这似乎与我丢失的数据相对应。 I have tried to unhide to no avail.
我试图取消隐藏,但无济于事。 Suggestions as to where to go next?
关于下一步去哪里的建议? Must I loop through the table or have I made an error in my destination?
我必须遍历表格还是在目的地出现错误? New at this, and 3rd world internet speed, along with inability to have books delivered makes this a tedious process.
这种新功能以及第三世界的互联网速度,加上无法交付书籍,使这一过程变得乏味。 Please bear with the NewBee.
请忍受NewBee。
New piece of information, I have found that if I unhide the entire sheet the correct data appears in the StaffTBL, of course the filter of the PermTBL also disappears, so apparently I was on the right track. 新的信息,我发现如果取消隐藏整个工作表,则正确的数据会出现在StaffTBL中,当然PermTBL的过滤器也会消失,所以显然我走在正确的轨道上。 Would still like comments and suggestions on programmatically (as opposed to manually) filtering PermTBL.
仍然希望以编程方式(而非手动方式)过滤PermTBL提出意见和建议。 I will continue to search sites for that, but any suggestions are appreciated.
我将继续在该站点上进行搜索,但是任何建议都值得赞赏。
Sub CopyData()
Dim t As ListObject
Dim t2 As ListObject
Set t = ActiveSheet.ListObjects("PermTBL")
Set t2 = ActiveSheet.ListObjects("StaffTBL")
' Remove all rows from StaffTBL table
If Not t2.DataBodyRange Is Nothing Then
t2.DataBodyRange.Rows.Delete
End If
' Filter Status by "A"
t.DataBodyRange.AutoFilter Field:=4, Criteria1:="A"
' Copy to first cell right below the table's header
t.DataBodyRange.Copy t2.Range(1).Offset(1)
' Remove filter from PermTBL table
t.DataBodyRange.AutoFilter
End Sub
UPDATE 更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.