如何根据月份过滤器自动更新表格

时间:2019-02-26 08:23:51

标签: vba excel-2010

图像中的表具有12个月的期间概述,在这种情况下,从2018年2月到2019年1月。下个月,该表将更新,结果从2018年3月到2019年2月,从APR 2018 2019年3月,依此类推。该表当前每月手动更新。在当前月份的情况下,我将不得不返回并过滤到当月前一个月的前几个月的数据。在更新表格的过程中,当宏更改列时,如何自动更新它,以便前几个月的月份过滤器发生变化?到目前为止,下面的宏允许我从这个范围内移动(C14:N19),但是您将看到,该过滤器是硬编码的,不是动态的。任何帮助将不胜感激

Sub LUUUP()

Dim i As Long i = 0 For x = 1 To 12 i = i + 1

    If x = 1 Then y = "C"
    If x = 2 Then y = "D"
    If x = 3 Then y = "E"
    If x = 4 Then y = "F"
    If x = 5 Then y = "G"
    If x = 6 Then y = "H"
    If x = 7 Then y = "I"
    If x = 8 Then y = "J"
    If x = 9 Then y = "K"
    If x = 10 Then y = "L"
    If x = 11 Then y = "M"
    If x = 12 Then y = "N"

ActiveSheet.ListObjects("Tableau1").Range.AutoFilter Field:=12, Criteria1:= _ xlFilterLastMonth, Operator:=xlFilterDynamic

Range("C1").Copy Sheets("feuil1").Select

Range(y & "14").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False

Next x End Sub

0 个答案:

没有答案