一张纸中的自动筛选表中的值大于另一张纸中的变量

时间:2019-06-05 21:37:22

标签: excel vba autofilter

基本--- File1包含Table1,而File2包含Table2。我的宏包含在File2中,它从Table1复制行并将其粘贴到Table2的底部。每次运行宏时,我都会在File2中记录一个时间戳。

特殊--我只想从表1复制那些包含日期的行(位于第16列),该行比我上次运行宏时在File2中记录的时间戳晚。

File1是ComboFile;表1是ComboWeekTable; File2是汇总; Table2是RollupWeekTable

Sub CopyToRollup()

Dim RollupWeekSheet As Worksheet
Set RollupWeekSheet = Workbooks("Tasks - Rollup").Sheets("Weekly")

Dim RollupWeekTable As ListObject
Set RollupWeekTable = RollupWeekSheet.ListObjects("Table1")

Dim RollupTimeStamp As String
RollupTimeStamp = RollupWeekSheet.Range("B3").Value



Dim ComboFile As Workbook
Set ComboFile = Workbooks.Open(ComboPath, ReadOnly:=True)
'Opens ComboFile as Read Only~~~~~~~~~~~

Dim ComboWeekSheet As Worksheet
Set ComboWeekSheet = ComboFile.Sheets("Weekly")

Dim ComboWeekTable As ListObject
Set ComboWeekTable = ComboWeekSheet.ListObjects("Table1")
'Define most variables~~~~~~~~~~~~~~



Dim LastRollupWeekRow As Long
Dim sh1Col As Integer
With RollupWeekSheet
sh1Col = .Range("Table1").Cells(1).Column
LastRollupWeekRow = .Cells(.Rows.Count, sh1Col).End(xlUp).Row
End With
'Move to the next empty row in Rollup Table 1.~~~~~~~~~~~~~~~~



With ComboWeekTable
.Range.AutoFilter Field:=16, Criteria1:=">" & RollupTimeStamp
.AutoFilter.Range.Copy
End With

With RollupWeekSheet
.Cells(LastRollupWeekRow + 1, sh1Col).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End With
'Filter ComboWeekTable column 16 for values greater than RollupTimeStamp, copy from ComboWeekTable only those rows added later than the timestamp, and paste them to the bottom of RollupWeekTable.~~~~~~~~~~~~~~~~



RollupWeekSheet.Range("B3").Value = DateTime.Now

ComboFile.Close savechanges:=False
'Record a new RollupTimeStamp and close ComboFile.~~~~~~~~~~~~~~~~

End Sub

它一直告诉我,我的自动筛选器出现“找不到命名争论”。我不确定自己在做什么错。任何帮助将不胜感激。

0 个答案:

没有答案