Sub SubmitData()
Dim FullName As String
Dim wsCustomersData As Worksheet, wsCustomerMainData As Worksheet
Dim wbCustomerRawData As Workbook
Dim rngCopyFrom As Range, rngCopyTo As Range
'-------------------------------------------------------------------------------------
' Settings
'-------------------------------------------------------------------------------------
Const FilePath As String = "C:\1.Martin\1.Work\Customers\October 2022\"
Const FileName As String = "Customer Raw data.xlsx"
'-------------------------------------------------------------------------------------
FullName = FilePath & FileName
Set wsCustomersData = ThisWorkbook.Worksheets("Customers Data")
'size the copy range (sheet must not be protected)
Set rngCopyFrom = wsCustomersData.Range("A1").CurrentRegion
On Error GoTo myerror
If Not Dir(FullName, vbDirectory) = vbNullString Then
Application.ScreenUpdating = False
Set wbCustomerRawData = Workbooks.Open(FullName, 0, False)
Set wsCustomerMainData = wbCustomerRawData.Worksheets("Customer Main Data")
'clear existing data
wsCustomerMainData.UsedRange.Offset(1).Clear
'size to destination range
Set rngCopyTo = wsCustomerMainData.Cells(1, 1).Resize(, rngCopyFrom.Columns.Count)
'copy header values
rngCopyTo.Value = rngCopyFrom.Rows(1).Value
'copy data to customer sheet
rngCopyFrom.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=rngCopyTo
Else
'file not found
Err.Raise 53
End If
ColorBanding wsCustomerMainData.UsedRange
myerror:
'close & if no error, save file
If Not wbCustomerRawData Is Nothing Then wbCustomerRawData.Close CBool(Err = 0)
Application.ScreenUpdating = True
'inform user
If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub
Sub ColorBanding(ByVal Target As Range)
Dim r As Range
'--------------------------------------------------------------------
' Banding Colours
'--------------------------------------------------------------------
Const OddRows As Long = 15189684, EvenRows As Long = 15917529
Const HeaderRow As Long = 12874308
'--------------------------------------------------------------------
For Each r In Target.Rows
r.Interior.Color = IIf(r.Row Mod 2 <> 0, OddRows, EvenRows)
Next r
'header row
Target.Rows(1).Interior.Color = HeaderRow
End Sub