Private Sub Worksheet_Change(ByVal Target As Range)
Dim h1, h2, high_pt As Double
Dim ht1, ht2, ht4, ht5, ht6 As Double
Dim t1, t2, t3, t4, t5 As String
t1 = "Interco Price Methodology and Incoterms"
ht1 = 27
t2 = "Affiliate selling to the Market's Distributor by Product Category"
ht2 = 26
t3 = "Business Flows"
ht4 = 46
t4 = "Factories and Brands"
ht5 = 56
t5 = "Royalties and Entrepreneur"
color_fill = 15
ActiveSheet.Rows.EntireRow.Hidden = False
Application.EnableEvents = False
Range("a2:Z500").Select
Selection.Interior.ColorIndex = 0
Range("A1").Select
Application.ScreenUpdating = False
If Target.Address = "$G$1" Then
On Error Resume Next
Call Add_Lines_Area(Title_Position(t1), Title_Position(t2), ht1)
Call Update_Array("price", Target.value)
high_pt = ActiveSheet.PivotTables("price").TableRange2.Rows.Count
Call Delete_Lines_Up(Title_Position(t2), ht1 - high_pt - 4)
Call Add_Lines_Area(Title_Position(t2), Title_Position(t3), ht2)
Call Update_Array("affiliate", Target.value)
high_pt = ActiveSheet.PivotTables("affiliate").TableRange2.Rows.Count
Call Delete_Lines_Up(Title_Position(t3), ht2 - high_pt - 4)
Call Add_Lines_Area(Title_Position(t3), Title_Position(t4), ht4)
Call Update_Array("flows", Target.value)
high_pt = ActiveSheet.PivotTables("flows").TableRange2.Rows.Count
Call Delete_Lines_Up(Title_Position(t4), ht4 - high_pt - 4)
Call Add_Lines_Area(Title_Position(t4), Title_Position(t5), ht5)
Call Update_Array("brand", Target.value)
high_pt = ActiveSheet.PivotTables("brand").TableRange2.Rows.Count
Call Delete_Lines_Up(Title_Position(t5), ht5 - high_pt - 4)
Call Update_Array("royalty", Target.value)
On Error GoTo 0
End If
ActiveSheet.PageSetup.PrintArea = "$A$1:$Z$1000"
On Error Resume Next
For j = ActiveSheet.HPageBreaks.Count To 1 Step -1
ActiveSheet.HPageBreaks(j).Delete
Next j
On Error GoTo 0
h1 = Title_Position(t1)
Rows(h1 + 2 & ":" & h1 + 4).Select
Selection.EntireRow.Hidden = True
h1 = Title_Position(t2)
Rows(h1 + 2 & ":" & h1 + 4).Select
Selection.EntireRow.Hidden = True
h1 = Title_Position(t3)
Rows(h1 + 2 & ":" & h1 + 4).Select
Selection.EntireRow.Hidden = True
h1 = Title_Position(t4)
Rows(h1 + 2 & ":" & h1 + 4).Select
Selection.EntireRow.Hidden = True
h1 = Title_Position(t5)
Rows(h1 + 2 & ":" & h1 + 4).Select
Selection.EntireRow.Hidden = True
h1 = Title_Position(t4)
Range("a" & h1).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
h1 = Title_Position(t5)
hight_pt = ActiveSheet.PivotTables("royalty").TableRange2.Rows.Count
If h1 + 1 + high_pt > 50 Then
Range("a" & h1).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
h1 = Title_Position(t2)
h2 = ActiveSheet.PivotTables("affiliate").TableRange2.Rows.Count
Range("D" & h1 + 5 & ":D" & h1 + h2 + 1).Select
Selection.Borders.LineStyle = xlNone
With Selection
.BorderAround LineStyle:=xlContinuous
.BorderAround Weight:=xlThin
.BorderAround ColorIndex = 1
End With
If Selection.Rows.Count > 1 Then
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End If
h1 = Title_Position(t3)
h2 = ActiveSheet.PivotTables("flows").TableRange2.Rows.Count
Range("E" & h1 + 6 & ":H" & h1 + h2 + 1).Select
With Selection.Font
.Name = "Arial Narrow"
.Size = 9
End With
Selection.Borders.LineStyle = xlNone
With Selection
.BorderAround LineStyle:=xlContinuous
.BorderAround Weight:=xlThin
.BorderAround ColorIndex = 1
End With
If Selection.Rows.Count > 1 Then
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End If
h1 = Title_Position(t4)
h2 = ActiveSheet.PivotTables("brand").TableRange2.Rows.Count
Range("G" & h1 + 5 & ":G" & h1 + h2 + 1).Select
Selection.Borders.LineStyle = xlNone
With Selection
.BorderAround LineStyle:=xlContinuous
.BorderAround Weight:=xlThin
.BorderAround ColorIndex = 1
End With
If Selection.Rows.Count > 1 Then
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End If
h1 = Title_Position(t5)
h2 = ActiveSheet.PivotTables("royalty").TableRange2.Rows.Count
Range("G" & h1 + 5 & ":G" & h1 + h2 + 1).Select
Selection.Borders.LineStyle = xlNone
With Selection
.BorderAround LineStyle:=xlContinuous
.BorderAround Weight:=xlThin
.BorderAround ColorIndex = 1
End With
If Selection.Rows.Count > 1 Then
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End If
Call Fill_Background(Title_Position(t1) + 5, "B", "F", 1, color_fill)
Call Fill_Background(Title_Position(t2) + 5, "B", "D", 1, color_fill)
Call Fill_Background(Title_Position(t3) + 5, "B", "E", 1, color_fill)
Call Fill_Background(Title_Position(t4) + 5, "B", "G", 1, color_fill)
Call Fill_Background(Title_Position(t5) + 5, "B", "G", 1, color_fill)
h1 = Title_Position(t5) + 2 + ActiveSheet.PivotTables("royalty").TableRange2.Rows.Count
ActiveSheet.PageSetup.PrintArea = "$A$1:$H$" & h1
With ActiveSheet.PageSetup
.Zoom = 70
End With
Range("a1").Select
Application.EnableEvents = True
End Sub