I am trying to populate vales in text boxes on a userform based on different conditions which are linked to combo boxes in the same userform.
After i write the same procedure for multiple conditions i get the error " Procedure too long.
I tried to write the code in a separate procedre and call it after every condition, however it doesn't calculate based on the selected values in the combo box.
After i write the same procedure for multiple conditions i get the error " Procedure too long.
I tried to write the code in a separate procedre and call it after every condition, however it doesn't calculate based on the selected values in the combo box.
HTML:
Private Sub Cmd_calc_Click()
Dim Masht As Worksheet
Dim i As Integer
Dim cbx1, cbx2, cbx3, cbx4, cbx5, cbx6 As String
J1 = 0
F1 = 0
M1 = 0
A1 = 0
M2 = 0
J2 = 0
J3 = 0
A2 = 0
S1 = 0
O1 = 0
N1 = 0
D1 = 0
cbx1 = Fr_P.cmb_Region.Value
cbx2 = Fr_P.Cmb_Entity.Value
cbx3 = Fr_P.Cmb_City.Value
cbx4 = Fr_P.Cmb_Prop.Value
cbx5 = Fr_P.Cmb_ExpsHd.Value
cbx6 = Fr_P.Cmb_ExpsCate.Value
For i = 2 To Masht.Range("A1").End(xlDown).Row
If cbx1 = "All Regions" And cbx2 = Empty And cbx3 = Empty And cbx4 = Empty And cbx5 = Empty And cbx6 = Empty Then
Jan = Masht.Range("G" & i).Value
Janb = Masht.Range("T" & i).Value
J1 = J1 + Jan
JB1 = JB1 + Janb
Feb = Masht.Range("H" & i).Value
Febb = Masht.Range("U" & i).Value
F1 = F1 + Feb
FB1 = FB1 + Febb
Mar = Masht.Range("I" & i).Value
Marb = Masht.Range("V" & i).Value
M1 = M1 + Mar
MB1 = MB1 + Marb
Apr = Masht.Range("J" & i).Value
Aprb = Masht.Range("W" & i).Value
A1 = A1 + Apr
AB1 = AB1 + Aprb
May = Masht.Range("K" & i).Value
Mayb = Masht.Range("X" & i).Value
M2 = M2 + May
MB2 = MB2 + Mayb
Jun = Masht.Range("L" & i).Value
Junb = Masht.Range("Y" & i).Value
J2 = J2 + Jun
JB2 = JB2 + Junb
Jul = Masht.Range("M" & i).Value
Julb = Masht.Range("Z" & i).Value
J3 = J3 + Jul
JB3 = JB3 + Julb
Aug = Masht.Range("N" & i).Value
Augb = Masht.Range("AA" & i).Value
A2 = A2 + Aug
AB2 = AB2 + Augb
Sep = Masht.Range("O" & i).Value
Sepb = Masht.Range("AB" & i).Value
S1 = S1 + Sep
SB1 = SB1 + Sepb
Oct = Masht.Range("P" & i).Value
Octb = Masht.Range("AC" & i).Value
O1 = O1 + Oct
OB1 = OB1 + Octb
Nov = Masht.Range("Q" & i).Value
Novb = Masht.Range("AD" & i).Value
N1 = N1 + Nov
NB1 = NB1 + Novb
Dec = Masht.Range("R" & i).Value
Decb = Masht.Range("AE" & i).Value
D1 = D1 + Dec
DB1 = DB1 + Decb
Jan = Masht.Range("G" & i).Value
Janb = Masht.Range("T" & i).Value
J1 = J1 + Jan
JB1 = JB1 + Janb
Feb = Masht.Range("H" & i).Value
Febb = Masht.Range("U" & i).Value
F1 = F1 + Feb
FB1 = FB1 + Febb
Mar = Masht.Range("I" & i).Value
Marb = Masht.Range("V" & i).Value
M1 = M1 + Mar
MB1 = MB1 + Marb
Apr = Masht.Range("J" & i).Value
Aprb = Masht.Range("W" & i).Value
A1 = A1 + Apr
AB1 = AB1 + Aprb
May = Masht.Range("K" & i).Value
Mayb = Masht.Range("X" & i).Value
M2 = M2 + May
MB2 = MB2 + Mayb
Jun = Masht.Range("L" & i).Value
Junb = Masht.Range("Y" & i).Value
J2 = J2 + Jun
JB2 = JB2 + Junb
Jul = Masht.Range("M" & i).Value
Julb = Masht.Range("Z" & i).Value
J3 = J3 + Jul
JB3 = JB3 + Julb
Aug = Masht.Range("N" & i).Value
Augb = Masht.Range("AA" & i).Value
A2 = A2 + Aug
AB2 = AB2 + Augb
Sep = Masht.Range("O" & i).Value
Sepb = Masht.Range("AB" & i).Value
S1 = S1 + Sep
SB1 = SB1 + Sepb
Oct = Masht.Range("P" & i).Value
Octb = Masht.Range("AC" & i).Value
O1 = O1 + Oct
OB1 = OB1 + Octb
Nov = Masht.Range("Q" & i).Value
Novb = Masht.Range("AD" & i).Value
N1 = N1 + Nov
NB1 = NB1 + Novb
Dec = Masht.Range("R" & i).Value
Decb = Masht.Range("AE" & i).Value
D1 = D1 + Dec
DB1 = DB1 + Decb
ElseIf cbx1 = "Masht.Range("A" & i).Value" And cbx2 = Empty And cbx3 = Empty And cbx4 = Empty And cbx5 = Empty And cbx6 = Masht.Range("E" & i).Value Then
Jan = Masht.Range("G" & i).Value
Janb = Masht.Range("T" & i).Value
J1 = J1 + Jan
JB1 = JB1 + Janb
Feb = Masht.Range("H" & i).Value
Febb = Masht.Range("U" & i).Value
F1 = F1 + Feb
FB1 = FB1 + Febb
Mar = Masht.Range("I" & i).Value
Marb = Masht.Range("V" & i).Value
M1 = M1 + Mar
MB1 = MB1 + Marb
Apr = Masht.Range("J" & i).Value
Aprb = Masht.Range("W" & i).Value
A1 = A1 + Apr
AB1 = AB1 + Aprb
May = Masht.Range("K" & i).Value
Mayb = Masht.Range("X" & i).Value
M2 = M2 + May
MB2 = MB2 + Mayb
Jun = Masht.Range("L" & i).Value
Junb = Masht.Range("Y" & i).Value
J2 = J2 + Jun
JB2 = JB2 + Junb
Jul = Masht.Range("M" & i).Value
Julb = Masht.Range("Z" & i).Value
J3 = J3 + Jul
JB3 = JB3 + Julb
Aug = Masht.Range("N" & i).Value
Augb = Masht.Range("AA" & i).Value
A2 = A2 + Aug
AB2 = AB2 + Augb
Sep = Masht.Range("O" & i).Value
Sepb = Masht.Range("AB" & i).Value
S1 = S1 + Sep
SB1 = SB1 + Sepb
Oct = Masht.Range("P" & i).Value
Octb = Masht.Range("AC" & i).Value
O1 = O1 + Oct
OB1 = OB1 + Octb
Nov = Masht.Range("Q" & i).Value
Novb = Masht.Range("AD" & i).Value
N1 = N1 + Nov
NB1 = NB1 + Novb
Dec = Masht.Range("R" & i).Value
Decb = Masht.Range("AE" & i).Value
D1 = D1 + Dec
DB1 = DB1 + Decb
Jan = Masht.Range("G" & i).Value
Janb = Masht.Range("T" & i).Value
J1 = J1 + Jan
JB1 = JB1 + Janb
Feb = Masht.Range("H" & i).Value
Febb = Masht.Range("U" & i).Value
F1 = F1 + Feb
FB1 = FB1 + Febb
Mar = Masht.Range("I" & i).Value
Marb = Masht.Range("V" & i).Value
M1 = M1 + Mar
MB1 = MB1 + Marb
Apr = Masht.Range("J" & i).Value
Aprb = Masht.Range("W" & i).Value
A1 = A1 + Apr
AB1 = AB1 + Aprb
May = Masht.Range("K" & i).Value
Mayb = Masht.Range("X" & i).Value
M2 = M2 + May
MB2 = MB2 + Mayb
Jun = Masht.Range("L" & i).Value
Junb = Masht.Range("Y" & i).Value
J2 = J2 + Jun
JB2 = JB2 + Junb
Jul = Masht.Range("M" & i).Value
Julb = Masht.Range("Z" & i).Value
J3 = J3 + Jul
JB3 = JB3 + Julb
Aug = Masht.Range("N" & i).Value
Augb = Masht.Range("AA" & i).Value
A2 = A2 + Aug
AB2 = AB2 + Augb
Sep = Masht.Range("O" & i).Value
Sepb = Masht.Range("AB" & i).Value
S1 = S1 + Sep
SB1 = SB1 + Sepb
Oct = Masht.Range("P" & i).Value
Octb = Masht.Range("AC" & i).Value
O1 = O1 + Oct
OB1 = OB1 + Octb
Nov = Masht.Range("Q" & i).Value
Novb = Masht.Range("AD" & i).Value
N1 = N1 + Nov
NB1 = NB1 + Novb
Dec = Masht.Range("R" & i).Value
Decb = Masht.Range("AE" & i).Value
D1 = D1 + Dec
DB1 = DB1 + Decb
Else
End If
Next i