0

我有 2 个工作簿。一个以 YYYYW**.xlsx 格式命名,其中 * 代表周数,另一个命名类似,但最后带有项目控制。第一个工作簿中有许多行包含许多值。它们的范围从 300--- 数字到 800--- 数字。这些也有一个交付日期以及项目是活跃的还是关闭的。

项目控制工作簿包含 3 张工作表,一张用于 2012 年项目,一张用于 2013 年项目,一张用于关闭。

我想问的是如何以编程方式获取数据范围并将它们传输到新工作簿中的相应工作表。

谢谢

Project|    Description             |   Delivery  |   Total Sales  |  
------------------------------------------------------------------------        
300661 |CCBS - HLP250               |   01/01/2012|  Active        |
------------------------------------------------------------------------      
300710 |STOCK - ITM250 ELECTRICS    |   01/01/2012|  Closed        |
------------------------------------------------------------------------      
300731 |Nirvana: 4th Piece packer   |   28/02/2012|  Closed        | 
------------------------------------------------------------------------     
300766 |STOCK - SATU                |   01/01/2012|  Active        | 
------------------------------------------------------------------------     
300767 |STOCK - HLP 250 CONVERSION  |   01/01/2012|  Active        | 
------------------------------------------------------------------------     
300768 |STOCK - PNEUMATIC, EMBOSSING|   01/01/2012|  Active        | 
------------------------------------------------------------------------     
412972 |I.T.M. BV                   |   23/05/2013|  Closed        |
------------------------------------------------------------------------      
412986 |I.T.M. BV                   |   17/07/2012|  Closed        | 
------------------------------------------------------------------------     
413001 |I.T.M. BV                   |   06/08/2012|  Closed        | 
------------------------------------------------------------------------     
510003 |Internal Project for issuing|   27/12/2013|  Active        | 
------------------------------------------------------------------------    
600161 |Tabak Invest  Kit & Conv    |   28/02/2012|  Closed        | 
------------------------------------------------------------------------     
600166 |UTC DUBAI                   |   10/01/2012|  Closed        | 
------------------------------------------------------------------------     
600168 |UTC HLP250 Conversion       |   20/02/2012|  Closed        | 
------------------------------------------------------------------------  

上述信息需要按交货年份排序,无论是打开的还是关闭的,并且一旦放入正确的表格中,就需要将其复制成如图所示的数字顺序。

在上面的示例中,由于交付日期和活动状态,项目 510003 将进入工作簿 2013,而 300661、3006、300767 和 300768 将全部进入 2012 年,其余项目将进入已关闭工作表,因为项目已完成并已关闭地位

4

1 回答 1

0

这应该开始了。您必须进行一些调整以匹配您的实际数据和文件,但结构应该是可靠的。

Option Explicit

Sub MoveIt()

Dim wkbData As Workbook, wkbPaste As Workbook

Set wkbData = ThisWorkbook
Set wkbPaste = Workbooks("ProjectControl")

With wkbData

    Dim wks As Worksheet
    Set wks = Sheets(1) 'assumes data is in sheet1

    With wks

        ' -> note that use of .usedrange implies data is in a table with no other _
            data or formatting in the worksheet
        .UsedRange.AutoFilter 4, "Closed"

        Dim rng As Range
        Set rng = Intersect(.UsedRange, .UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible)

        rng.Copy wkbPaste.Sheets("Closed")

        .UsedRange.AutoFilter 4, "Active"
        .UsedRange.AutoFilter 3, xlFilterThisYear

        Set rng = Intersect(.UsedRange, .UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible)

        rng.Copy wkbPaste.Sheets("2012").Range("A1")

        .UsedRange.AutoFilter 4, "Active"
        .UsedRange.AutoFilter 3, xlFilterNextYear

        Set rng = Intersect(.UsedRange, .UsedRange.Offset(1)).SpecialCells(xlCellTypeVisible)

        rng.Copy wkbPaste.Sheets("2013").Range("A1")

    End With

End With

End Sub
于 2012-10-24T13:57:19.350 回答