pradeephatti
New Member
- Joined
- Jul 11, 2019
- Messages
- 1
Hi All,
Need help on below , I need to copy data to master workbook from different workbook VBA, and need selected column to copy , when condition met, have created code, but some error, can some one help on this please
V-1
[TABLE="class: grid, width: 811"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]UNIT[/TD]
[TD]Revised CRD[/TD]
[TD]Style[/TD]
[TD]Master PO[/TD]
[TD]Market[/TD]
[TD]DC Code[/TD]
[TD]DC Name[/TD]
[TD]Color Code[/TD]
[TD]Color Name[/TD]
[/TR]
[TR]
[TD]Vendor-1[/TD]
[TD]15-Aug[/TD]
[TD]ABCD[/TD]
[TD]1234[/TD]
[TD]MX[/TD]
[TD]1005[/TD]
[TD]Mexico[/TD]
[TD]W23[/TD]
[TD]DARK DRY[/TD]
[/TR]
</tbody>[/TABLE]
V-2
[TABLE="class: grid, width: 820, align: left"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]UNIT[/TD]
[TD]Date[/TD]
[TD]Style[/TD]
[TD]Master PO[/TD]
[TD]Market[/TD]
[TD]DC Code[/TD]
[TD]DC Name[/TD]
[TD]Color Code[/TD]
[TD]Color Name[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]BCDA[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_2W[/TD]
[TD] Outdoor Mexico[/TD]
[TD]1[/TD]
[TD]BLACK[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]A1VTY[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]Japan[/TD]
[TD]244[/TD]
[TD]CUB[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]SLDD[/TD]
[TD]874508[/TD]
[TD]AP[/TD]
[TD]W00410_1R[/TD]
[TD]China[/TD]
[TD]918[/TD]
[TD]BRITISH KHAKI[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]SDLDS[/TD]
[TD]1423797[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]us[/TD]
[TD]433[/TD]
[TD]DARK SAPPHIRE[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]FAF[/TD]
[TD]1973086[/TD]
[TD]AP[/TD]
[TD]W00410_1R[/TD]
[TD] Outdoor Mexico[/TD]
[TD]433[/TD]
[TD]TBW23 DARK DRY[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]LSFG[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]Japan[/TD]
[TD]590[/TD]
[TD]CASSEL EARTH[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 820"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD]have done code but some error,
Sub AddToMaster()
'this macro goes IN the master workbook
Dim wsMaster As Worksheet, Sheet1 As Workbook
Dim NextRow As Long, lastrow As Long
Dim FileName As String
Dim FolderPath As String
Dim n As Long
Dim i
Set wsMaster = ThisWorkbook.Sheets("Sheet1")
'Specify the folder path
FolderPath = "C:\Users\hattip\Desktop\DPR"
'specifying file name
FileName = Dir(FolderPath & "*.xls*")
Do While FileName <> ""
NextRow = wsMaster.Range("A" & Rows.Count).End(xlUp).Row + 1
Set wbDATA = Workbooks.Open(FolderPath & FileName)
With wbDATA.Sheets("Sheet1")
lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
' If LastRow > 5 Then
For i = 2 To lastrow
If Cells(i, 11).Value = "Mexico" Then
.Range("A2:I" & i).Copy
wsMaster.Range("A" & NextRow).PasteSpecial xlPasteValues
'Set NextRow = NextRow
Loop
End With
Next i
FileName = Dir()
Application.ScreenUpdating = True
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
Need help on below , I need to copy data to master workbook from different workbook VBA, and need selected column to copy , when condition met, have created code, but some error, can some one help on this please
V-1
[TABLE="class: grid, width: 811"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]UNIT[/TD]
[TD]Revised CRD[/TD]
[TD]Style[/TD]
[TD]Master PO[/TD]
[TD]Market[/TD]
[TD]DC Code[/TD]
[TD]DC Name[/TD]
[TD]Color Code[/TD]
[TD]Color Name[/TD]
[/TR]
[TR]
[TD]Vendor-1[/TD]
[TD]15-Aug[/TD]
[TD]ABCD[/TD]
[TD]1234[/TD]
[TD]MX[/TD]
[TD]1005[/TD]
[TD]Mexico[/TD]
[TD]W23[/TD]
[TD]DARK DRY[/TD]
[/TR]
</tbody>[/TABLE]
V-2
[TABLE="class: grid, width: 820, align: left"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]UNIT[/TD]
[TD]Date[/TD]
[TD]Style[/TD]
[TD]Master PO[/TD]
[TD]Market[/TD]
[TD]DC Code[/TD]
[TD]DC Name[/TD]
[TD]Color Code[/TD]
[TD]Color Name[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]BCDA[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_2W[/TD]
[TD] Outdoor Mexico[/TD]
[TD]1[/TD]
[TD]BLACK[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]A1VTY[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]Japan[/TD]
[TD]244[/TD]
[TD]CUB[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]SLDD[/TD]
[TD]874508[/TD]
[TD]AP[/TD]
[TD]W00410_1R[/TD]
[TD]China[/TD]
[TD]918[/TD]
[TD]BRITISH KHAKI[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]SDLDS[/TD]
[TD]1423797[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]us[/TD]
[TD]433[/TD]
[TD]DARK SAPPHIRE[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]FAF[/TD]
[TD]1973086[/TD]
[TD]AP[/TD]
[TD]W00410_1R[/TD]
[TD] Outdoor Mexico[/TD]
[TD]433[/TD]
[TD]TBW23 DARK DRY[/TD]
[/TR]
[TR]
[TD]Vendor-2[/TD]
[TD]3-May[/TD]
[TD]LSFG[/TD]
[TD]325219[/TD]
[TD]AP[/TD]
[TD]W00410_4E[/TD]
[TD]Japan[/TD]
[TD]590[/TD]
[TD]CASSEL EARTH[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 820"]
<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[/TR]
[TR]
[TD]have done code but some error,
Sub AddToMaster()
'this macro goes IN the master workbook
Dim wsMaster As Worksheet, Sheet1 As Workbook
Dim NextRow As Long, lastrow As Long
Dim FileName As String
Dim FolderPath As String
Dim n As Long
Dim i
Set wsMaster = ThisWorkbook.Sheets("Sheet1")
'Specify the folder path
FolderPath = "C:\Users\hattip\Desktop\DPR"
'specifying file name
FileName = Dir(FolderPath & "*.xls*")
Do While FileName <> ""
NextRow = wsMaster.Range("A" & Rows.Count).End(xlUp).Row + 1
Set wbDATA = Workbooks.Open(FolderPath & FileName)
With wbDATA.Sheets("Sheet1")
lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
' If LastRow > 5 Then
For i = 2 To lastrow
If Cells(i, 11).Value = "Mexico" Then
.Range("A2:I" & i).Copy
wsMaster.Range("A" & NextRow).PasteSpecial xlPasteValues
'Set NextRow = NextRow
Loop
End With
Next i
FileName = Dir()
Application.ScreenUpdating = True
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]