Combobox linked to Custom Views
Thank you for the help but I still get a run-time error 91, saying that
object variable or with block is not set.
Can you advise?
Thank you.
"Dave Peterson" wrote:
I would add the options to the combobox a single time--maybe in the
workbook_open event?
Option Explicit
Private Sub Workbook_Open()
With Worksheets("Sheet1").bgCmbox
.Clear 'existing options
.AddItem "(All)"
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
End With
End Sub
Then since you're using the same options as the custom view names, you can use
something like this in the combobox change event:
Option Explicit
Private Sub bgCmbox_Change()
On Error Resume Next
Me.Parent.CustomViews(bgCmbox.Value).Show
If Err.Number < 0 Then
Err.Clear
MsgBox "Design error!"
End If
On Error GoTo 0
End Sub
MK wrote:
Hello, I have trouble with linking combobox selection to the custom views
I've created. Please help!
In advance, thank you.
I created an ActiveX control combobox and have teh following code:
Dim bgCmbox As ComboBox
Private Sub ComboBox1_Change()
'With Worksheets(1)
Dim bgCmbox As ComboBox
bgCmbox.AddItem " ", 1
bgCmbox.AddItem "(All)", 2
bgCmbox.AddItem "A", 3
bgCmbox.AddItem "B", 4
bgCmbox.AddItem "C", 5
bgCmbox.AddItem "D", 6
bgCmbox.AddItem "E", 7
bgCmbox.AddItem "F", 8
If bgCmbox.Value = "(All)" Then
ActiveWorkbook.CustomViews("All").Show
ElseIf bgCmbox.Value = "A" Then
ActiveWorkbook.CustomViews("A").Show
ElseIf bgCmbox.Value = "B" Then
ActiveWorkbook.CustomViews("B").Show
ElseIf bgCmbox.Value = "C" Then
ActiveWorkbook.CustomViews("C").Show
ElseIf bgCmbox.Value = "D" Then
ActiveWorkbook.CustomViews("D").Show
ElseIf bgCmbox.Value = "E" Then
ActiveWorkbook.CustomViews("E").Show
ElseIf bgCmbox.Value = "F" Then
ActiveWorkbook.CustomViews("F").Show
End If
End Sub
--
Dave Peterson
.
|