[英]How to consolidate data of Specific columns from multiple sheet to one sheet using excel macro when the required columns are not in same order
我在具有10个项目表的Excel工作表中对不同项目有缺陷,例如工作表A,工作表B,工作表C,工作表D,工作表E,工作表F等
每张纸都有不同的列, 缺陷编号,缺陷摘要,严重性,优先级,报告者,分配给者,状态,日期等
我想从所有工作表到所有工作表的列( 所有工作表中的列都不相同 )中(缺陷合并)
缺陷编号,缺陷摘要,严重性,优先级和状态
当单击一个按钮时,我需要从A,B和C项目表中看到所有上述字段,而不是从所有项目中看到。
希望有人能帮上忙。
注意 :我可以手动复制粘贴它,但是要求是到目前为止,我们只需要在工作簿中创建一个名称为“缺陷合并”的excel工作表,这就是所有:(对宏而言有点新
系统详细信息:Windows 7和Microsoft提供2010。
正如我对您的问题的解释一样。 如果您的要求有所不同,这应该为您提供一个起点。
将以下代码附加到您的按钮上...
Option Explicit
Sub consolidate()
Dim myInSht As Worksheet
Dim myOutSht As Worksheet
Dim aRow As Range
Dim aCol As Range
Dim myInCol As Range
Dim myOutCol As Range
Dim cell As Range
Dim iLoop As Long, jLoop As Long
jLoop = 2
' loop through the worksheets
For Each myInSht In ActiveWorkbook.Worksheets
' pick only the worksheets of interest
If myInSht.Name = "PrjA" Or myInSht.Name = "PrjB" Or myInSht.Name = "PrjC" Then
' find the columns of interest in the worksheet
For Each aCol In myInSht.UsedRange.Columns
Set myOutCol = Nothing
If aCol.Cells(1, 1).Value = "Defect id" Then Set myOutCol = Sheets("Consolidated").Range("A:A")
If aCol.Cells(1, 1).Value = "Defect summary" Then Set myOutCol = Sheets("Consolidated").Range("B:B")
If aCol.Cells(1, 1).Value = "severity" Then Set myOutCol = Sheets("Consolidated").Range("C:C")
If aCol.Cells(1, 1).Value = "priority" Then Set myOutCol = Sheets("Consolidated").Range("D:D")
If aCol.Cells(1, 1).Value = "status" Then Set myOutCol = Sheets("Consolidated").Range("E:E")
If Not myOutCol Is Nothing Then
' don't move the top line, it contains the headers - no data
Set myInCol = aCol
Set myInCol = myInCol.Offset(1, 0).Resize(myInCol.Rows.Count - 1, myInCol.Columns.Count)
' transfer data from the project tab to the consolidated tab
iLoop = jLoop
For Each aRow In myInCol.Rows
myOutCol.Cells(iLoop, 1).Value = aRow.Cells(1, 1).Value
iLoop = iLoop + 1
Next aRow
End If
Next aCol
End If
If iLoop > jLoop Then jLoop = iLoop
Next myInSht
End Sub
项目A的内容...
项目B的内容...
项目C的内容...
在运行合并例程后...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.