Hi Genius People,
I have the below code running for a sheet where I am collating data from various sheets.
The macro is running fine but the problems comes when it is pasting the values in the master sheet, where the last rows of the data are empty. Like in the below table the macro will paste po number till a3 but thereafter it will pick the PO number from the other sheet and will paste right under a3 thereby creating conflict in the table. I want that it should paste the data in each row relating to that very sheet. I know it is confusing but I am not able to attach the file to make it more specific. Thanks
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Po number[/TD]
[TD]part number[/TD]
[TD]status[/TD]
[TD]qty[/TD]
[/TR]
[TR]
[TD]a1[/TD]
[TD]1234[/TD]
[TD]packed[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]a2[/TD]
[TD][/TD]
[TD]picked[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a3[/TD]
[TD]1121[/TD]
[TD][/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1212[/TD]
[TD]despatched[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]43445[/TD]
[TD]received[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]3333[/TD]
[TD]packed[/TD]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
I have the below code running for a sheet where I am collating data from various sheets.
The macro is running fine but the problems comes when it is pasting the values in the master sheet, where the last rows of the data are empty. Like in the below table the macro will paste po number till a3 but thereafter it will pick the PO number from the other sheet and will paste right under a3 thereby creating conflict in the table. I want that it should paste the data in each row relating to that very sheet. I know it is confusing but I am not able to attach the file to make it more specific. Thanks
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Po number[/TD]
[TD]part number[/TD]
[TD]status[/TD]
[TD]qty[/TD]
[/TR]
[TR]
[TD]a1[/TD]
[TD]1234[/TD]
[TD]packed[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]a2[/TD]
[TD][/TD]
[TD]picked[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]a3[/TD]
[TD]1121[/TD]
[TD][/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]1212[/TD]
[TD]despatched[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]43445[/TD]
[TD]received[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]3333[/TD]
[TD]packed[/TD]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub Get_Info_By_Headers()
Dim sPath As String
Dim sFil As String
Dim owb As Workbook
Dim twb As Workbook
Dim ch
Dim j As Long, a As Long
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
ch = Array("po number", "part number", "status", "quantity")
Set twb = ThisWorkbook
sPath = "C:\Users\dipak\Desktop\CRASH REPORT\"
sFil = Dir(sPath & "*.xl*")
Do While sFil <> "" And sFil <> twb.Name
Set owb = Workbooks.Open(sPath & sFil)
With owb.Sheets("data")
For j = LBound(ch) To UBound(ch)
a = .Rows(1).Find(ch(j), , , 1).Column
.Range(.Cells(2, a), .Cells(.Cells(.Rows.Count, a).End(xlUp).Row, a)).Copy twb.Sheets("report").Cells(Rows.Count, j + 1).End(xlUp).Offset(1)
Next j
End With
owb.Close False 'Close no save
sFil = Dir
Loop
With Application
.Calculation = xlAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub