abdo meghari
Well-known Member
- Joined
- Aug 3, 2021
- Messages
- 612
- Office Version
- 2019
Hi experts,
I need add some lines to this code
first before export data to Elmarghanie Brand .xlsm file should clear contents data from A2:E
second should copy data for column A2:A from open file contains Worksheets("TABLE 1") to sheet REPORT for Elmarghanie Brand .xlsm file into column A2:A
the code will export data from open file contains Worksheets("TABLE 1") to closed Elmarghanie Brand .xlsm file contains REORT sheet
here is the code
I need add some lines to this code
first before export data to Elmarghanie Brand .xlsm file should clear contents data from A2:E
second should copy data for column A2:A from open file contains Worksheets("TABLE 1") to sheet REPORT for Elmarghanie Brand .xlsm file into column A2:A
the code will export data from open file contains Worksheets("TABLE 1") to closed Elmarghanie Brand .xlsm file contains REORT sheet
here is the code
VBA Code:
Sub OpenFilesFromFolder1()
Dim ExtBk As Workbook
Dim IntBk As Workbook
Dim FolderPath As String
Dim FilePath As String
Dim lRow As Long
Dim Rng1 As Range, Rng2 As Range
Set IntBk = ActiveWorkbook
lRow = IntBk.Worksheets("TABLE 1").Cells(Rows.Count, 1).End(xlUp).Row
FolderPath = "C:\Users\MY-NAME\Downloads\BRIDGESTONE REPORT\"
FilePath = Dir(FolderPath & "Elmarghanie Brand .xlsm")
If FilePath <> "" Then
Set ExtBk = Workbooks.Open(FolderPath & FilePath)
End If
Application.ScreenUpdating = False
For i = 2 To lRow
ExtBk.Worksheets("REPORT").Cells(i, 1).Value = IntBk.Worksheets("TABLE 1").Cells(i, 1).Value
Next
Set Rng1 = IntBk.Worksheets("TABLE 1").Range("B2:E" & lRow)
Set Rng2 = ExtBk.Worksheets("REPORT").Range("C2:F" & lRow)
Rng1.Copy
Rng2.PasteSpecial xlPasteValues
Application.ScreenUpdating = True
Application.DisplayAlerts = False
ExtBk.Save
ExtBk.Close
Application.DisplayAlerts = True
End Sub
thanks