NARAYANK991
Excel Ninja
Hi ,
Sorry , but the uploaded file is a .xlsx file , which cannot have any code in it.
Narayan
Sorry , but the uploaded file is a .xlsx file , which cannot have any code in it.
Narayan
Sub quartersummary()
'
' quartersummary Macro
' variables
' name of the worksheet, period TY LY, quarters, datarange for ty and ly,shift rows for category, shift cols for country, shift row
'and col for changing quarters
Dim catrow As Integer ' row variable for category
Dim startcol As Integer ' fix start column for this year and last year
Dim shiftcol As Integer 'shift column to change for country
Dim colrange As Integer ' define column for selecting data range
Dim passforQ As Integer 'quarter runs
Dim passforY As Integer 'runs for period
Dim P1, P2 As String 'to set the column to select start and end match periods while offsetting
Dim formulastring As String ' this is the string to define the formula and workaround the character limit
Dim spanstart, spanend As Integer 'to set the span for offsetting
category = Array("insect", "air care", "home cleaning", "auto care", "shoe care") 'array to select category
country = Array("cambodia", "laos", "myanmar", "brunei") 'array to select worksheet for country
fy17 = Array("01jul_fy17", "03sep_fy17", "04oct_fy17", "06dec_fy17", "07jan_fy17", "09mar_fy17", "10apr_fy17", "12jun_fy17") 'array to define the periods to choose from while _
offsetting ty
fy16 = Array("01jul", "03sep", "04oct", "06dec", "07jan", "09mar", "10apr", "12jun") 'array to define the periods to choose from while _
offsetting ly
For passforQ = 3 To 30 Step 9
For passforY = 1 To 2
Select Case passforY
Case Is = 1
startcol = 2
colrange = 47
Case Is = 2
startcol = 7
colrange = 34
End Select
Select Case passforQ And passforY
Case Is = 3 And 1
P1 = fy17(0)
P2 = fy17(1)
Case Is = 12 And 1
P1 = fy17(2)
P2 = fy17(3)
Case Is = 21 And 1
P1 = fy17(4)
P2 = fy17(5)
Case Is = 30 And 1
P1 = fy17(6)
P2 = fy17(7)
Case Is = 3 And 2
P1 = fy16(0)
P2 = fy16(1)
Case Is = 12 And 2
P1 = fy16(2)
P2 = fy16(3)
Case Is = 21 And 2
P1 = fy16(4)
P2 = fy16(5)
Case Is = 30 And 2
P1 = fy16(6)
P2 = fy16(7)
End Select
For shiftcol = startcol To startcol + 3
Select Case shiftcol
Case Is = startcol
country = country(0)
spanstart = 4
spanend = 119
Case Is = startcol + 1
country = country(1)
spanstart = 4
spanend = 136
Case Is = startcol + 2
country = country(2)
spanstart = 3
spanend = 156
Case Is = startcol + 3
country = country(3)
spanstart = 4
spanend = 262
End Select
For catrow = 3 To 7
formulastring = "=sum(offset(" & "'" & country & "'!" & "r" & spanstart & "c" & colrange & ":r" & spanend & "c" _
& colrange + 11 & ",0,(match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & _
colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)-1)" & "," & (spanend - spanstart + 1) & _
",(match(" & """" & P2 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & colrange & ":r" _
& spanstart - 1 & "c" & colrange + 11 & ",0)-match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & _
spanstart - 1 & "c" & colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)+1))*(" & "'" & country & "'!" _
& "r" & spanstart & "c3:r" & spanend & "c3=""" & category(catrow - 3) & """))/1000/36.11"
With Sheets("category summary by quarter").Cells(catrow, startcol)
.FormulaArray = formulastring
End With
Next catrow
Next shiftcol
Next passforY
Next passforQ
End Sub
Sub quartersummary()
'
' quartersummary Macro
' variables
' name of the worksheet, period TY LY, quarters, datarange for ty and ly,shift rows for category, shift cols for country, shift row
'and col for changing quarters
Dim catrow As Integer ' row variable for category
Dim startcol As Integer ' fix start column for this year and last year
Dim shiftcol As Integer 'shift column to change for country
Dim colrange As Integer ' define column for selecting data range
Dim passforQ As Integer 'quarter runs
Dim passforY As Integer 'runs for period
Dim P1, P2, country As String 'to set the column to select start and end match periods while offsetting
Dim formulastring As String ' this is the string to define the formula and workaround the character limit
Dim spanstart, spanend As Integer 'to set the span for offsetting
Dim fx As Integer 'variable to set the fx rate for fy17 and fy16
category = Array("insect", "air care", "cleaner", "auto care", "shoe care") 'array to select category
selcountry = Array("cambodia", "laos", "myanmar", "brunei") 'array to select worksheet for country
fy17 = Array("01jul_fy17", "03sep_fy17", "04oct_fy17", "06dec_fy17", "07jan_fy17", "09mar_fy17", "10apr_fy17", "12jun_fy17") 'array to define the periods to choose from while _
offsetting ty
fy16 = Array("01jul", "03sep", "04oct", "06dec", "07jan", "09mar", "10apr", "12jun") 'array to define the periods to choose from while _
offsetting ly
For passforQ = 3 To 30 Step 9
For passforY = 1 To 2
Select Case passforY
Case Is = 1
startcol = 2
colrange = 47
fx = 36.11
Case Is = 2
startcol = 7
colrange = 34
fx = 33.4
End Select
Select Case passforQ And passforY
Case Is = 3, 1
P1 = fy17(0)
P2 = fy17(1)
Case Is = 12, 1
P1 = fy17(2)
P2 = fy17(3)
Case Is = 21, 1
P1 = fy17(4)
P2 = fy17(5)
Case Is = 30, 1
P1 = fy17(6)
P2 = fy17(7)
Case Is = 3, 2
P1 = fy16(0)
P2 = fy16(1)
Case Is = 12, 2
P1 = fy16(2)
P2 = fy16(3)
Case Is = 21, 2
P1 = fy16(4)
P2 = fy16(5)
Case Is = 30, 2
P1 = fy16(6)
P2 = fy16(7)
End Select
For shiftcol = startcol To startcol + 3
Select Case shiftcol
Case Is = 2, 7
country = selcountry(0)
spanstart = 4
spanend = 119
Case Is = 3, 8
country = selcountry(1)
spanstart = 4
spanend = 136
Case Is = 4, 9
country = selcountry(2)
spanstart = 3
spanend = 156
Case Is = 5, 10
country = selcountry(3)
spanstart = 4
spanend = 262
End Select
For catrow = passforQ To passforQ + 4
If country <> "brunei" Then
formulastring = "=sum(offset(" & "'" & country & "'!" & "r" & spanstart & "c" & colrange & ":r" & spanend & "c" _
& colrange + 11 & ",0,(match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & _
colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)-1)" & "," & (spanend - spanstart + 1) & _
",(match(" & """" & P2 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & colrange & ":r" _
& spanstart - 1 & "c" & colrange + 11 & ",0)-match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & _
spanstart - 1 & "c" & colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)+1))*(" & "'" & country & "'!" _
& "r" & spanstart & "c3:r" & spanend & "c3=""" & category(catrow - 3) & """))/1000/" & fx & ""
Else
formulastring = "=sum(offset(" & "'" & country & "'!" & "r" & spanstart & "c" & colrange & ":r" & spanend & "c" _
& colrange + 11 & ",0,(match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & _
colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)-1)" & "," & (spanend - spanstart + 1) & _
",(match(" & """" & P2 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & colrange & ":r" _
& spanstart - 1 & "c" & colrange + 11 & ",0)-match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & _
spanstart - 1 & "c" & colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)+1))*(" & "'" & country & "'!" _
& "r" & spanstart & "c3:r" & spanend & "c3=""" & category(catrow - 3) & """))/1000"
End If
With Sheets("category summary by quarter").Cells(catrow, shiftcol)
.FormulaArray = formulastring
End With
Next catrow
Next shiftcol
Next passforY
Next passforQ
End Sub
Sub quartersummary()
'
' quartersummary Macro
' variables
' name of the worksheet, period TY LY, quarters, datarange for ty and ly,shift rows for category, shift cols for country, shift row
'and col for changing quarters
Dim catrow As Integer ' row variable for category
Dim startcol As Integer ' fix start column for this year and last year
Dim shiftcol As Integer 'shift column to change for country
Dim colrange As Integer ' define column for selecting data range
Dim passforQ As Integer 'quarter runs
Dim passforY As Integer 'runs for period
Dim P1, P2, country As String 'to set the column to select start and end match periods while offsetting
Dim formulastring As String ' this is the string to define the formula and workaround the character limit
Dim spanstart, spanend As Integer 'to set the span for offsetting
Dim fx As Integer 'variable to set the fx rate for fy17 and fy16
Category = Array("insect", "air care", "cleaner", "auto care", "shoe care") 'array to select category
selcountry = Array("cambodia", "laos", "myanmar", "brunei") 'array to select worksheet for country
fy17 = Array("01jul_fy17", "03sep_fy17", "04oct_fy17", "06dec_fy17", "07jan_fy17", "09mar_fy17", "10apr_fy17", "12jun_fy17") 'array to define the periods to choose from while _
offsetting ty
fy16 = Array("01jul", "03sep", "04oct", "06dec", "07jan", "09mar", "10apr", "12jun") 'array to define the periods to choose from while _
offsetting ly
For passforQ = 3 To 30 Step 9
For passforY = 1 To 2
Select Case passforY
Case Is = 1
startcol = 2
colrange = 47
fx = 36.11
Case Is = 2
startcol = 7
colrange = 34
fx = 33.4
End Select
Select Case passforQ + passforY
Case Is = 4
P1 = fy17(0)
P2 = fy17(1)
Case Is = 13
P1 = fy17(2)
P2 = fy17(3)
Case Is = 22
P1 = fy17(4)
P2 = fy17(5)
Case Is = 31
P1 = fy17(6)
P2 = fy17(7)
Case Is = 5
P1 = fy16(0)
P2 = fy16(1)
Case Is = 14
P1 = fy16(2)
P2 = fy16(3)
Case Is = 23
P1 = fy16(4)
P2 = fy16(5)
Case Is = 32
P1 = fy16(6)
P2 = fy16(7)
End Select
For shiftcol = startcol To startcol + 3
Select Case shiftcol
Case Is = 2, 7
country = selcountry(0)
spanstart = 4
spanend = 119
Case Is = 3, 8
country = selcountry(1)
spanstart = 4
spanend = 136
Case Is = 4, 9
country = selcountry(2)
spanstart = 3
spanend = 156
Case Is = 5, 10
country = selcountry(3)
spanstart = 4
spanend = 262
End Select
For catrow = passforQ To passforQ + 4
rowval = catrow Mod 9
If country <> "brunei" Then
formulastring = "=sum(offset(" & "'" & country & "'!" & "r" & spanstart & "c" & colrange & ":r" & spanend & "c" _
& colrange + 11 & ",0,(match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & _
colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)-1)" & "," & (spanend - spanstart + 1) & _
",(match(" & """" & P2 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & colrange & ":r" _
& spanstart - 1 & "c" & colrange + 11 & ",0)-match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & _
spanstart - 1 & "c" & colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)+1))*(" & "'" & country & "'!" _
& "r" & spanstart & "c3:r" & spanend & "c3=""" & Category(rowval - 3) & """))/1000/" & fx & ""
Else
formulastring = "=sum(offset(" & "'" & country & "'!" & "r" & spanstart & "c" & colrange & ":r" & spanend & "c" _
& colrange + 11 & ",0,(match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & _
colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)-1)" & "," & (spanend - spanstart + 1) & _
",(match(" & """" & P2 & """" & "," & "'" & country & "'!" & "r" & spanstart - 1 & "c" & colrange & ":r" _
& spanstart - 1 & "c" & colrange + 11 & ",0)-match(" & """" & P1 & """" & "," & "'" & country & "'!" & "r" & _
spanstart - 1 & "c" & colrange & ":r" & spanstart - 1 & "c" & colrange + 11 & ",0)+1))*(" & "'" & country & "'!" _
& "r" & spanstart & "c3:r" & spanend & "c3=""" & Category(rowval - 3) & """))/1000"
End If
With Sheets("category summary by quarter").Cells(catrow, shiftcol)
.FormulaArray = formulastring
End With
Next catrow
Next shiftcol
Next passforY
Next passforQ
End Sub