copy data to master workbook from different workbook VBA, and need selected column to copy , when condition met

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]
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top