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
UNITRevised CRDStyleMaster POMarketDC CodeDC NameColor CodeColor Name
Vendor-115-AugABCD1234MX1005MexicoW23DARK DRY

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

V-2
UNITDateStyleMaster POMarketDC CodeDC NameColor CodeColor Name
Vendor-23-MayBCDA325219APW00410_2W Outdoor Mexico1BLACK
Vendor-23-MayA1VTY325219APW00410_4EJapan244CUB
Vendor-23-MaySLDD874508APW00410_1RChina918BRITISH KHAKI
Vendor-23-MaySDLDS1423797APW00410_4Eus433DARK SAPPHIRE
Vendor-23-MayFAF1973086APW00410_1R Outdoor Mexico433TBW23 DARK DRY
Vendor-23-MayLSFG325219APW00410_4EJapan590CASSEL EARTH

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

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



<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,873
Messages
6,122,029
Members
449,061
Latest member
TheRealJoaquin

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