jawaharprm
Member
Hi All,
Below given code is copy the data from download file "Cust rep report-CA Only_07_18_22.xlsb" to Macro File "RepAlignments_Macro_File.xlsb"
this code will take file as mentioned path in code.
Enclosed file for your reference.
Thanks
Below given code is copy the data from download file "Cust rep report-CA Only_07_18_22.xlsb" to Macro File "RepAlignments_Macro_File.xlsb"
this code will take file as mentioned path in code.
Enclosed file for your reference.
Thanks
Code:
Option Explicit
Public cust_search As Worksheet, ocust As String
Const path_ As String = "C:\Jawahar Works\New folder\Marcor Works & Projects\Canada Project\New folder"
Const be_path_ As String = "C:\Jawahar Works\New folder\Marcor Works & Projects\Canada Project\New folder"
Const dtEarliest = #1/1/2019# 'stops loop if file is not found by this date
Sub CopyData_Can()
'On Error Resume Next
Dim cell As Range
Dim pos_ As Integer, posSpace As String
Dim cansheet, fNames As Worksheet
Dim be_cansheet, be_repSheet As Worksheet
Dim prname, prHandle, prEmail As String
Dim repFirst, repLast, repFull As String
Dim repname, repEmail As String
Dim oThisWB, cxWB, ccWB, raWB As String
Dim dtTestDate As Date
Dim sStartWb As String
Dim t, t_, k As Long
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set cansheet = ThisWorkbook.Sheets(6)
cansheet.Cells.ClearContents
oThisWB = ActiveWorkbook.Name
'Run only if file updated Customer Extract file is found
dtTestDate = Date + 1
While ActiveWorkbook.Name = oThisWB And dtTestDate >= dtEarliest
ocust = "Cust rep report-CA Only_" & Format(dtTestDate, "MM_DD_YY") & ".xlsb"
On Error Resume Next
Workbooks.Open Filename:=path_ & ocust, ReadOnly:=True
dtTestDate = dtTestDate - 1
On Error GoTo 0
Wend
'On Error Resume Next
If Not ActiveWorkbook.Name = oThisWB Then
'Copy US Customer Extract
cxWB = ActiveWorkbook.Name
With Workbooks(cxWB)
fNames.Cells(2, 1) = cxWB
.Sheets(6).Cells.AutoFilter
'WR 20210714 - .Sheets(1).Range("A:A,C:C,E:F,N:J,Q:R,V:W,Y:Y,AB:AB,AF:AF").EntireColumn.Copy _
Destination:=custSheet.Columns("A")
.Sheets(6).Range("A:A,C:C,E:F,H:I,N:Q,T:U,W:W,Z:Z,AD:AD,AF:AF").EntireColumn.Copy _
Destination:=cansheet.Columns("A")
'Enter date of document below
'cansheet.Range("R2") = dtTestDate + 1
End With
Workbooks(cxWB).Close False
End If
'######## BIO EXPRESS EXTRACT ########
Workbooks(oThisWB).Activate
dtTestDate = Date + 1
While ActiveWorkbook.Name = oThisWB And dtTestDate >= dtEarliest
On Error Resume Next
Workbooks.Open Filename:=be_path_ & "Cust rep report-CA Only - BioExpress Only " & Format(dtTestDate, "MM_DD_YY") & ".xlsb", ReadOnly:=True
dtTestDate = dtTestDate - 1
On Error GoTo 0
Wend
'On Error Resume Next
If Not ActiveWorkbook.Name = oThisWB Then
'Copy US Customer Extract
cxWB = ActiveWorkbook.Name
With Workbooks(cxWB)
fNames.Cells(3, 1) = cxWB
.Sheets(6).Cells.AutoFilter
.Sheets(6).Range("A:B,D:E,G:H,M:O,T:U, W:W,AB:AB,AF:AF,AO:AQ").EntireColumn.Copy _
Destination:=be_cansheet.Columns("A")
'Enter date of document below
'cansheet.Range("R2") = dtTestDate + 1
End With
'Rename headers of "BE Cust Extract" worksheet
With be_cansheet
.Range("A1") = "BE Soldto"
.Range("B1") = "BE Customer"
.Range("C1") = "BE Name 1"
.Range("D1") = "BE Name 2"
.Range("E1") = "BE Street"
.Range("F1") = "BE Street 2"
.Range("G1") = "BE City"
.Range("H1") = "BE Rg"
.Range("I1") = "BE Postal Code"
.Range("J1") = "BE Cust ID"
.Range("K1") = "BE Cust ID Desc"
.Range("L1") = "BE Inds Desc"
.Range("M1") = "BE Rep No"
.Range("N1") = "BE Creation Date"
End With
Workbooks(cxWB).Close False
End If
End Sub