Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel宏将行移到底部_Excel_Vba - Fatal编程技术网

Excel宏将行移到底部

Excel宏将行移到底部,excel,vba,Excel,Vba,我以前从未使用过excel宏,只是被赋予了编写宏的任务,该宏在输入的完成日期后10天将已完成的任务移动到文档底部(即,如果它在4月14日完成,并且该日期是输入到完成列中的日期,则整行移动到文档底部) 下面是我用来练习的表格 Current_Date Id Samp1 Samp2 Samp3 Samp4 Samp5 Samp6 Completed_Date Completed_Plus_10 Real_C+10 Post 5/2/2016 1 a1 ab1 b1

我以前从未使用过excel宏,只是被赋予了编写宏的任务,该宏在输入的完成日期后10天将已完成的任务移动到文档底部(即,如果它在4月14日完成,并且该日期是输入到完成列中的日期,则整行移动到文档底部)

下面是我用来练习的表格

Current_Date  Id  Samp1 Samp2 Samp3 Samp4 Samp5 Samp6 Completed_Date Completed_Plus_10  Real_C+10  Post
5/2/2016       1    a1    ab1   b1   bc1    c1    1     2/18/2016        2/28/2016      2/28/2016    Y 
5/2/2016       2    a2    ab2   b2   bc2    c2    2     1/10/1900           N
5/2/2016       3    a3    ab3   b3   bc3    c3    3     1/10/1900           N
5/2/2016       4    a4    ab4   b4   bc4    c4    4     4/21/2016        5/1/2016       5/1/2016     Y
5/2/2016       5    a5    ab5   b5   bc5    c5    5     1/10/1900           N
5/2/2016       6    a6    ab6   b6   bc6    c6    6     1/10/1900           N
5/2/2016       7    a7    ab7   b7   bc7    c7    7     3/14/2016        3/24/2016      3/24/2016    Y
5/2/2016       8    a8    ab8   b8   bc8    c8    8     1/10/1900           N
5/2/2016       9    a9    ab9   b9   bc9    c9    9     1/10/1900           N
5/2/2016      10   a10   ab10  b10  bc10   c10   10     5/2/2016         5/12/2016      5/12/2016    N
5/2/2016      11   a11   ab11  b11  bc11   c11   11     1/10/1900           N
5/2/2016      12   a12   ab12  b12  bc12   c12   12     1/10/1900           N
5/2/2016      13   a13   ab13  b13  bc13   c13   13     1/10/1900           N
5/2/2016      14   a14   ab14  b14  bc14   c14   14     1/10/1900           N
5/2/2016      15   a15   ab15  b15  bc15   c15   15     1/10/1900           N
5/2/2016      16   a16   ab16  b16  bc16   c16   16     1/10/1900           N
5/2/2016      17   a17   ab17  b17  bc17   c17   17     1/10/1900           N
5/2/2016      18   a18   ab18  b18  bc18   c18   18     1/10/1900           N
5/2/2016      19   a19   ab19  b19  bc19   c19   19     1/10/1900           N
5/2/2016      20   a20   ab20  b20  bc20   c20   20     1/10/1900           N

这里有一个小宏,这样您就不必从空页开始: 我的表格如下:

Date        id  samp1   samp2   Complete date
05.02.2016  2   abc     abc     asd
10.02.2016  4   ghi     ghi     01.02.2016
07.02.2016  3   def     def     asd
11.05.2016  5   jkl     jkl     06.05.2016
我使用了宏记录器并将第二行复制到表的末尾。然后我使用“查找并选择”>“转到特殊”>选择“空白”>“输入”。然后我删除了它们(在这里找到:)。 在录制的宏中,我添加了变量LastRow(使其动态)

宏的基本功能是:

  • 复制范围(“A3:E3”)
  • 穿过它到桌子的尽头
  • 删除空行
您可以使用此宏并根据您的问题进行调整。循环行,如果日期(从第1列开始)减去日期(从第5列开始)大于10,则复制,否则不执行任何操作


我希望这有帮助

请看。我已经看过如何提问网站。但我对宏非常陌生,完全不知道从哪里开始,也不知道它是如何工作的。我曾尝试在其他网站上查找说明,但仍然迷路。这是为了工作——如果我只是想自己弄明白(没有最后期限),我会花更多的时间通过反复试验来练习,直到我做对了或者陷入困境。但由于这是为了工作,我没有时间这么做。我曾尝试创建自己的宏,但我不知道如何将我尝试过的内容复制到此网站。复制方式与复制表格的方式相同。我使用了“记录宏”,但后来丢失了试图找到它的最接近的代码。
Sub mv()
'
' mv Makro
'
' Tastenkombination: Strg+Umschalt+A
'
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    'here you sould add a loop over the rows and an the if statement
    Range("A3:E3").Select
    Selection.Cut
    Range("A" & LastRow + 1).Select
    ActiveSheet.Paste
    'and here the end of the if statement and the loop        

    Range("A1").Select
    Application.CommandBars("Selection and Visibility").Visible = False
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.delete

End Sub