excel - 将过滤的单元格范围从一个工作表复制到另一个工作表的最后一行
问题描述
我正在尝试在 1 个工作表(“2。选择研究特定表格”)上过滤一系列数据(通过使用 L 列中的“是”)并将数据复制到另一个工作表的最后一行(“3。工作表” )。我正在使用下面的代码。到目前为止,代码过滤了第一个工作表上的数据,但数据不会复制到第二个工作表。
提前感谢您的任何帮助。
Sub FilterAndCopy2()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim LastRow As Long, LastRow2 As Long
Dim TARGetSheet As Worksheet, TKSheet As Worksheet
Set TARGetSheet = Sheets("2. Select Study-Specific Forms") 'Set sheet where filtered data is
Set TKSheet = Sheets("3. Worksheet") ' Set Sheet name to copy data to
LastRow = TARGetSheet.Range("L" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
LastRow2 = TKSheet.Range("A" & Rows.Count).End(xlUp).Row + 1 ' Determine the next empty row in order to paste the data
With TARGetSheet
.AutoFilterMode = False
With .Range("G7", "L" & LastRow)
.AutoFilter
.AutoFilter Field:=6, Criteria1:="Yes"
End With
End With
TARGetSheet.Range("G7", "L" & LastRow).Copy
TKSheet.Range("A" & LastRow2).PasteSpecial (xlPasteAll)
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
解决方案
推荐阅读
- c# - 如何在 Xamarin 上创建类别和子类别?
- search - 图搜索如何返回路径?
- linux - 为什么 kthreaddi 在 debian(Docker 容器)AWS ECS 中消耗 100% CPU
- javascript - 为什么 Angular 11 中的延迟加载组件是在新页面中加载的,而不是在侧边栏右侧的主页面中?
- java - 使用 onMessage (OkHttp) 的输出?
- joomla - 为什么在 Joomla 文章粒子中不显示别名创建的?
- sql - 将 PostgreSQL 行号添加到一列
- google-chrome - 如何修复 Windows 中 Chromium 浏览器的构建错误?
- python - 在 tkinter 中显示视频
- python - 使用 Spyder 调试远程 python 文件