LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Combobox linked to Custom Views

I don't understand why changing the combobox on that sheet isn't functional when
the workbook opens.

When/how do you populate the combobox?

MK wrote:

Thank you, Dave. It seems like I'm making this super complicated.

I do want to show different custom views based on user preference. However,
I want to set up the workbook, such that the user doesn't have to run a
macro. Instead, I would like the combobox be functional once the user opens
the workbook. Is it something feasible?

Again, thank you for all your help!!!

"Dave Peterson" wrote:

I thought that cboView was a combobox that displayed the custom view that the
user chose. That's why you were using the cboView_Change event.

If you want the Workbook_Open event to show a particular custom view (not loop
through them all), then just show the custom view that you want.

Option Explicit
Private Sub Workbook_Open()
Me.CustomViews("whateverviewyouwant").Show
End sub

MK wrote:

I want the combobox to work when the user opens the workbook. I don't want
the user to go through additional steps of running any macros, but rather
make the combobox functional as the workbook is opened.

In the workbook_open sub I just copied over the code that originally was in
Sheet1 under sub cboView_Change().

The code worked in Sheet1 sub cboView__Change, but the user had to run the
cboView_Change macro for it to function. As I stated above, I really want to
avoid that. Could you please advise?

Thank you for all your help!!!

MK

"Dave Peterson" wrote:

I don't understand what you're doing in the workbook_open event.

I think you'll need to give more info.

MK wrote:

I ran my Private sub cboView_Change in sheet 1 and it worked well. However, I
had to initiate a macro in order for it to work. When I copied the code into
ActiveWorksheet, it didn't work. This is what I have copied over with some
edits.

Private Sub Workbook_Open()

Dim cboView As ComboBox
Dim views As Range
Dim i As Variant
i = Array(views)


Set views = Sheet5.Range("views")
'cboView.List = views.Value

For Each i In views
Me.Sheets(1).CustomViews(cboView.Value).Show

Exit For
Next i

End Sub

I get error '91, Object or with variable is missing.

PURPOSE OF THE MACRO: I want it to run such that when the user selects the
view, that view is displayed. Also, I would like to set it up in a such a way
that the user doesn't have to initiate any macros but can use the combobox
once the worksheet is opened.

Thank you very much for all your help with this!!!

Best,

MK

"Dave Peterson" wrote:

The combobox was populated in the workbook_Open event.

Did you allow macros to run when you opened the workbook?


MK wrote:

Hi Dave,

When I ran the code for "Private Sub Cbo_View...", I didn't have anything in
the drop down box to choose from. So, I kept getting the error message.

"Dave Peterson" wrote:

First, you have to tell me why this didn't work:

Option Explicit
Private Sub cboView_Change()

Dim myStr as string
myStr = me.cboview.value
if lcase(mystr) = lcase("(all)") then
myStr = "All"
end if

On Error Resume Next
Me.Parent.CustomViews(myStr).Show
If Err.Number < 0 Then
Err.Clear
MsgBox "Design error!"
End If
On Error GoTo 0

End Sub

After you do that, I'll show you how to use:

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"
.ListIndex = 0 'show the first item in the dropdown
End With

End Sub


MK wrote:

Dave,

I actually figured it out.

My code is:

Option Explicit

Sub cboView_Change()

Dim views As Range
Dim i As Variant
i = Array(views)

Set views = Sheet5.Range("views")
cboView.List = views.Value

For Each i In views
ThisWorkbook.CustomViews(cboView.Value).Show
Exit For
Next i
Reset

End Sub

The only thing i'd like to add is to set "All" view as default. Could you
help me out there?

Thank you,

Maria

"MK" wrote:

Hi Dave,

I keep adjusting the code based on some of your feedback and also what I've
found in the forum. This is the code I have and for some reason I get an
error that the object doesn't support the property/method. Again, thank you
very much for your help!

Sub cboView_Change()
Dim views As Range

Set views = Sheet5("Control").Range("views")
Me.cboView.List = views.Value
' Me.cboView.RowSource = views.Address(external:=True)

On Error Resume Next
Me.Parent.CustomViews(views).Show
If Err.Number < 0 Then
Err.Clear
MsgBox "Design error!"
End If
On Error GoTo 0

End Sub



"Dave Peterson" wrote:

Remove the declaration for cboView. You don't need it.

But you did have to name the combobox on Sheet1 cboView. Did you do that?

And I see why you changed my suggestion for the _change procedure. I didn't
notice the "(All)" vs "All" naming difference.

You could use:

Option Explicit
Private Sub cboView_Change()

Dim myStr as string
myStr = me.cboview.value
if lcase(mystr) = lcase("(all)") then
myStr = "All"
end if

On Error Resume Next
Me.Parent.CustomViews(myStr).Show
If Err.Number < 0 Then
Err.Clear
MsgBox "Design error!"
End If
On Error GoTo 0

End Sub

I wouldn't want to use all those elseif's that end up using the view based on
the name seen in the combobox.



MK wrote:

Hi Dave,

I might be missing some declarations. But here it is. Thank you for your
help!
Dim cboView As ComboBox

Option Explicit
Private Sub Workbook_Open()

With Worksheets("Sheet1").cboView
.Clear 'existing options
.AddItem "(All)"
.AddItem "A"
.AddItem "B"
.AddItem "C"
.AddItem "D"
.AddItem "E"
.AddItem "F"
End With

End Sub

Option Explicit
Private Sub cboView_Change()


If cboView.Value = "(All)" Then
ActiveWorkbook.CustomViews("All").Show

ElseIf cboView.Value = "A" Then
ActiveWorkbook.CustomViews("A").Show

ElseIf cboView.Value = "B" Then
ActiveWorkbook.CustomViews("B").Show

ElseIf cboView.Value = "C" Then
ActiveWorkbook.CustomViews("C").Show

ElseIf cboView.Value = "D" Then
ActiveWorkbook.CustomViews("D").Show

ElseIf cboView.Value = "E" Then
ActiveWorkbook.CustomViews("E").Show

ElseIf cboView.Value = "F" Then
ActiveWorkbook.CustomViews("F").Show

End If
End Sub

"Dave Peterson" wrote:

What's the name of the worksheet that owns the combobox?

What's the name of the combobox that you want to use?

If you changed the code, post what you used and indicate what line caused the
error.



MK wrote:

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:


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Views Mervyn Thomas[_2_] Setting up and Configuration of Excel 0 September 5th 08 04:42 PM
Custom Views Michael Gudyka Excel Discussion (Misc queries) 6 June 26th 08 06:54 PM
Custom Views Khardy3352 New Users to Excel 2 June 22nd 08 01:37 PM
custom views Mac Excel Worksheet Functions 1 October 5th 06 06:38 PM
Custom views Wagi123 Excel Discussion (Misc queries) 2 February 10th 06 10:03 AM


All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"