Option Explicit
Sub App_A()
' Get the range
Dim rg, ra As Range
Dim i, j As Integer
Dim lastRow As Long
Dim bl, dm As String
Dim dd As Long
Dim sl, rpt As String
sl = "SALES PROFILE FOR THE MONTH OF "
rpt = "REVENUE INTO ACCOUNT WITH JP THE BANK IN "
bl = shdata.Range("C2")
dd = shdata.Range("D2")
dm = shdata.Range("E2")
TurnOffFunctionality
shappa.Range("A1").Value = "COMPANY"
shappa.Range("A2").Value = sl & UCase(bl) & " " & dd & " AND EXPECTED"
shappa.Range("A3").Value = rpt & UCase(dm) & " " & dd
shappa.Range("B5").Value = UCase("crude oil export - ") & shdata.Range("AA5") & UCase(" account")
Set rg = shdata.Range("A10").CurrentRegion
' Clear the filter in case one exists
rg.AutoFilter
Dim CriteriaRange As Range, CopyRange As Range
Set CriteriaRange = shdata.Range("AA4:AA5")
Set CopyRange = shappa.Range("A6:R6")
' Filter column 10 on the city
rg.AdvancedFilter xlFilterCopy, CriteriaRange, CopyRange
' Clear the filter when finished
rg.AutoFilter
' Activate the Report sheet
shappa.Activate
With shappa
lastRow = shappa.Cells(Rows.Count, 1).End(xlUp).Row
Set ra = shappa.Range("A7: R" & lastRow)
For j = 7 To lastRow
For i = 10 To 17
Cells(lastRow + 1, i) = Cells(lastRow + 1, i) + Application.WorksheetFunction.Sum(Cells(j, i))
Next i
Next j
ra.Font.Name = "Albertus Medium"
ra.Font.Size = 16
ra.Font.Bold = False
Cells(lastRow + 1, 2) = "SUB-TOTAL"
If Cells(lastRow + 1, 10) = 0 Then
Cells(lastRow + 1, 11).Value2 = ""
Else
Cells(lastRow + 1, 11) = Cells(lastRow + 1, 12) / Cells(lastRow + 1, 10)
End If
Cells(lastRow + 1, 15) = ""
Cells(lastRow + 1, 10).NumberFormat = "#,##0;-#,##0"
Cells(lastRow + 1, 11).NumberFormat = "#,##0.0000;-#,##0.0000"
Cells(lastRow + 1, 12).NumberFormat = "#,##0.00"
Cells(lastRow + 1, 13).NumberFormat = "#,##0.00"
Cells(lastRow + 1, 14).NumberFormat = "#,##0.00"
Cells(lastRow + 1, 16).NumberFormat = "#,##0.00"
Cells(lastRow + 1, 17).NumberFormat = "#,##0.00"
Rows(lastRow + 1).Font.Name = "Albertus Medium"
Rows(lastRow + 1).Font.Size = 16
Rows(lastRow + 1).Font.Bold = True
With Selection.Font
.Color = vbBlack
.Bold = False
End With
With Selection.Interior
.Color = xlNone
End With
With Selection.Borders(xlEdgeLeft)
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.Weight = xlThin
End With
Dim llRow, llCol, colNum, Column As Long
Dim Rng As Range
.Range("B1:R" & lastRow).Columns.AutoFit
.Range("A1:R" & lastRow).Rows.AutoFit
'.Range(.cells(lr).Interior.Color = rgbLightBlue
llRow = .Cells(.Rows.Count, 2).End(xlUp).Row
llCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
Set Rng = shappa.Range(Cells(llRow, 18), Cells(llRow, llCol))
Rng.Interior.Color = rgbLightBlue
Rng.BorderAround Weight:=xlThick
End With
AppA_1.Range("a1:s200").ClearContents
shappa.Activate
shappa.Range("A1").Select
shappa.Range("A1:R" & lastRow + 1).Copy Destination:=AppA_1.Range("A1")
'shappa.Range("A1:R" & lastRow + 1).Copy
'AppA_1.Range("a1").PasteSpecial Paste:=xlPasteFormats
AppA_1.Range("B1:R" & lastRow).Columns.AutoFit
AppA_1.Range("A1:R" & lastRow).Rows.AutoFit
'AppA_1.Range(Cells(Rows.Count, "A").End(xlUp).Offset(3), Cells(Rows.Count, "A")).EntireRow.Clear
AppA_1.Activate
AppA_1.Range("A1").Select
TurnOnFunctionality
End Sub