[英]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
I have defects for different project in an excel sheet with 10 project sheets eg sheet A, Sheet B Sheet C ,Sheet D ,sheet E,Sheet F etc 我在具有10个项目表的Excel工作表中对不同项目有缺陷,例如工作表A,工作表B,工作表C,工作表D,工作表E,工作表F等
Each sheet has different columns, Defect id, defect summary, severity, priority, reported by, assigned to, status, date etc 每张纸都有不同的列, 缺陷编号,缺陷摘要,严重性,优先级,报告者,分配给者,状态,日期等
I want following columns (which is NOT IN SAME ORDER in all sheets ) from all sheets to one sheet(defectconsolidation) 我想从所有工作表到所有工作表的列( 所有工作表中的列都不相同 )中(缺陷合并)
Defect id,Defect summary,severity,priority and status 缺陷编号,缺陷摘要,严重性,优先级和状态
When clicked a button , I need to see all above fields from JUST A,B and C project sheet and not from all project. 当单击一个按钮时,我需要从A,B和C项目表中看到所有上述字段,而不是从所有项目中看到。
hope some one will help. 希望有人能帮上忙。
Note : I can copy paste it manually but the requirement is we need to have a macro so far just created a excel sheet with name "defect consolidation" in my workbook thats all :( am bit new to macro 注意 :我可以手动复制粘贴它,但是要求是到目前为止,我们只需要在工作簿中创建一个名称为“缺陷合并”的excel工作表,这就是所有:(对宏而言有点新
system details : windows 7 and microsoft offer 2010. 系统详细信息:Windows 7和Microsoft提供2010。
This does as I interpreted your question. 正如我对您的问题的解释一样。 This should provide you a starting point if your requirements are a little different. 如果您的要求有所不同,这应该为您提供一个起点。
Attach the following code to your button ... 将以下代码附加到您的按钮上...
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
I used the following to test ... The consolidated tab before consolidation ... 我使用以下工具测试...合并之前的“合并”选项卡...
Project A contents ... 项目A的内容...
Project B contents ... 项目B的内容...
Project C contents ... 项目C的内容...
And after running the consolidation routine ... 在运行合并例程后...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.