Hi,
I have a few ComboBoxes on each tab. The contents of dropdown lists are hierarchical. For instance, State ->cities -> boroughes and so on. What I want is if I pick a state, I want to see the cities only in that state; if pick a city, I want to see all the boroughes in that city instead of all the boroughes. Ex: NY->NYC->(Bronx, Manhattan, Brooklyn and etc.)
I used the following code to get what I want:
Private Sub distbox_click()
Application.EnableEvents = False
Application.ScreenUpdating = False
Select Case distbox.Text
Case "CMAA"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmaa"
Case "CMAB"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmab"
Case "CMAC"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmac"
Case Else
regbox.Text = ""
terrbox.ListFillRange = "territory_name"
End Select
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
It was working fine until I clicked the Graph buttons. The selected tab started shaking and trembling; if I was on the Graph tab, the curves on the tab would come out column by column instead of show itself all at once.
I feels like there is some conflict among the events but Application.EnableEvents won't help.
If I get rid of the code above, everything is back to normal.
I am sure it has something to do with the code that creates the graphs but I cannot find the problems. The charts are to graph the 12 month trending of some products. Here is the main code for the graphs:
Sub GraphCore(showtab, maintab, product, mkttc As String, cnum As Double)
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
Sheets(showtab).Visible = True
Dim headr As Variant, i
headr = Range("a13:dz13").Value
For i = 1 To UBound(headr, 2)
If LCase(headr(1, i)) = mkttc Then
mkttccol = i
ElseIf LCase(headr(1, i)) = product Then
startcol = i
End If
Next
Sheets(maintab).Select
srw = Selection.Row
totsmtc = Range(Cells(srw, mkttccol), Cells(srw, mkttccol + cnum))
gheader = Range(Cells(12, 1), Cells(12, 4))
grtitle = Range(Cells(srw, 1), Cells(srw, 4))
For x = 0 To mkttccol - startcol - cnum Step 12
For i = 0 To 11
scl_prd = startcol + i + x
scl_mtc = mkttccol + i
'MsgBox srw & "*" & scl_prd & "*" & scl_mtc
pct = Cells(srw, scl_prd) / Cells(srw, scl_mtc)
z = x / 12 + 24
Sheets(showtab).Cells(z, i + 3) = pct
Next
Next
Sheets(showtab).Select
Range("aa1:al1") = totsmtc
Range("aa2:ad2") = gheader
Range("aa3:ad3") = grtitle
Range("az1:az1") = maintab
Range("C24:N31").NumberFormat = "0.00%"
Range("a32:a38").EntireRow.Hidden = False
Application.ScreenUpdating = True
Application.EnableEvents = True
On Error GoTo 0
End Sub
Thanks in advance.
I have a few ComboBoxes on each tab. The contents of dropdown lists are hierarchical. For instance, State ->cities -> boroughes and so on. What I want is if I pick a state, I want to see the cities only in that state; if pick a city, I want to see all the boroughes in that city instead of all the boroughes. Ex: NY->NYC->(Bronx, Manhattan, Brooklyn and etc.)
I used the following code to get what I want:
Private Sub distbox_click()
Application.EnableEvents = False
Application.ScreenUpdating = False
Select Case distbox.Text
Case "CMAA"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmaa"
Case "CMAB"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmab"
Case "CMAC"
regbox.Text = "CMA"
terrbox.ListFillRange = "terr_cmac"
Case Else
regbox.Text = ""
terrbox.ListFillRange = "territory_name"
End Select
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
It was working fine until I clicked the Graph buttons. The selected tab started shaking and trembling; if I was on the Graph tab, the curves on the tab would come out column by column instead of show itself all at once.
I feels like there is some conflict among the events but Application.EnableEvents won't help.
If I get rid of the code above, everything is back to normal.
I am sure it has something to do with the code that creates the graphs but I cannot find the problems. The charts are to graph the 12 month trending of some products. Here is the main code for the graphs:
Sub GraphCore(showtab, maintab, product, mkttc As String, cnum As Double)
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
Sheets(showtab).Visible = True
Dim headr As Variant, i
headr = Range("a13:dz13").Value
For i = 1 To UBound(headr, 2)
If LCase(headr(1, i)) = mkttc Then
mkttccol = i
ElseIf LCase(headr(1, i)) = product Then
startcol = i
End If
Next
Sheets(maintab).Select
srw = Selection.Row
totsmtc = Range(Cells(srw, mkttccol), Cells(srw, mkttccol + cnum))
gheader = Range(Cells(12, 1), Cells(12, 4))
grtitle = Range(Cells(srw, 1), Cells(srw, 4))
For x = 0 To mkttccol - startcol - cnum Step 12
For i = 0 To 11
scl_prd = startcol + i + x
scl_mtc = mkttccol + i
'MsgBox srw & "*" & scl_prd & "*" & scl_mtc
pct = Cells(srw, scl_prd) / Cells(srw, scl_mtc)
z = x / 12 + 24
Sheets(showtab).Cells(z, i + 3) = pct
Next
Next
Sheets(showtab).Select
Range("aa1:al1") = totsmtc
Range("aa2:ad2") = gheader
Range("aa3:ad3") = grtitle
Range("az1:az1") = maintab
Range("C24:N31").NumberFormat = "0.00%"
Range("a32:a38").EntireRow.Hidden = False
Application.ScreenUpdating = True
Application.EnableEvents = True
On Error GoTo 0
End Sub
Thanks in advance.