1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| Sub Margin()
Columns("W:X").Delete
Columns("U:U").Delete
Columns("I:S").Delete
Columns("G:G").Delete
Columns("E:E").Delete
Columns("B:C").Delete
Columns("A:A").ColumnWidth = 5.86
Columns("B:B").ColumnWidth = 9
Columns("E:E").ColumnWidth = 9.43
Columns("F:F").ColumnWidth = 6.14
Columns("G:G").ColumnWidth = 8.43
Columns("H:H").ColumnWidth = 5.71
Columns("I:I").ColumnWidth = 6.71
Columns("J:J").ColumnWidth = 9
Columns("I:I").ColumnWidth = 9
Columns("J:J").ColumnWidth = 9
With Range("E2:H1000")
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignBottom
End With
Range("I1") = "Margin"
Range("J1") = "Margin%"
Dim last_row As Long
last_row = Cells(Rows.Count, 2).End(xlUp).Row
Range("I2").Formula = "=[@[Retail Price]]-[@[Cost (base)]]"
Range("J2").Formula = "=([@Margin]/[@[Retail Price]])*100"
Range("J2").NumberFormat = "#,##0.00"
If last_row = 2 Then GoTo AfterAutoFill
Range("i2").AutoFill Destination:=Range("i2:i" & last_row)
Range("J2").AutoFill Destination:=Range("J2:J" & last_row)
AfterAutoFill:
Set plg = Range("e:h")
plg.Replace What:=".", Replacement:=",", LookAt:=xlPart
plg.Replace What:=",", Replacement:=".", LookAt:=xlPart
plg.Range("e:h").NumberFormat = "0.00"
Range("f2").End(xlDown).Offset(1).Select
ActiveCell.FormulaR1C1 = "=SUM(R" & ActiveCell.Offset(-1, 0).End(xlUp).Row & "C" & ActiveCell.Column & ":R" & ActiveCell.Row - 1 & "C" & ActiveCell.Column & ")"
Range("h2").End(xlDown).Offset(1).Select
ActiveCell.FormulaR1C1 = "=SUM(R" & ActiveCell.Offset(-1, 0).End(xlUp).Row & "C" & ActiveCell.Column & ":R" & ActiveCell.Row - 1 & "C" & ActiveCell.Column & ")"
ActiveSheet.PageSetup.Orientation = xlLandscape
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 0
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
End Sub |
Partager