Computing.Net > Forums > Office Software > Excel combobox code

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel combobox code

Reply to Message Icon

Name: ipsquared
Date: July 31, 2007 at 08:30:27 Pacific
OS: XP
CPU/Ram: NA
Product: Excel
Comment:

When I select a list value on an Excel form combobox that I created I want to go to another worksheet. For example, list box values are country names. For each country I have a worksheet with info on that country. When select a country on combobox list want to go to that country worksheet. What code do I need to enter? I have tried:

Sub DropDown1_Change()

If DropDown1.Value = "USA" Then
Sheets("USA").Select
End If

If DropDown2.Value = "Norway" Then
Sheets("Norway").Select
End If

End Sub

Get runtime error 424 Object required message with line highlighted: If DropDown1.Value = "USA" Then Thankyou for any help!




Sponsored Link
Ads by Google

Response Number 1
Name: rhawk7938
Date: July 31, 2007 at 17:59:11 Pacific
Reply:

Instead of Sheets it should be Worksheets:

Worksheets("USA").Select


0

Response Number 2
Name: DerbyDad03
Date: July 31, 2007 at 19:50:44 Pacific
Reply:

rhawk7938:

I don't believe that that is the problem. If it were, the Object Required error would highlight the Sheets("USA").Select line, not the If DropDown1.Value = "USA" line.

Just as an FYI, either Sheets("USA") or Worksheets("USA") can be used in this instance.

The Sheets collection refers to all sheets, (both chart sheets and worksheets) in a workbook while the Worksheets collection refers to worksheets only. In most (all?) cases where a sheet is being referenced by it's name, either Sheets or Worksheets can be used. However, if the OP was refering to the sheet by it's number, then Worksheets(X) might not be same sheet as Sheets(X) if there were chart sheets present.

I know this doesn't help the OP, but I just thought I would pass that along for future reference.



0

Response Number 3
Name: DerbyDad03
Date: July 31, 2007 at 19:56:09 Pacific
Reply:

ipsquared:

Do you need to use a ComboBox? A data validation list and a Worksheet_Change macro might accomplish your goal. For example...

Create a Data Validation list in B1 containing your values.
Right click the sheet tab and paste in this code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" Then
Select Case Target.Value
Case "USA"
Sheets("USA").Activate
Case "Norway"
Sheets("Norway").Activate
End Select
End If
End Sub


0

Response Number 4
Name: ipsquared
Date: August 1, 2007 at 09:31:52 Pacific
Reply:

Re: prior comment: Do you need to use a ComboBox?. Good question, but yes I would like to. I am actually creating a workbook with many worksheets where I set up hyperlinks to other worksheets in the workbook from a FRONT PAGE worksheet. One of the "hyperlinks" I'd like to change to a combo box so can "hyperlink" to the worksheet that the dropdown list value corresponds to. I don't know why my original code doesn't work. Seems like it should. Right now I have a hyperlink to another worksheet where I list the country values in cells in a cloumn. From this "list" values can hyperlink to the corresponding worksheet. Combobox would be cleaner. Thanks for the responses everyone!


0

Response Number 5
Name: DerbyDad03
Date: August 1, 2007 at 12:06:16 Pacific
Reply:

Before I can offer a solution to the ComboBox code question I need to know how you created the ComboBox - from the Forms toolbar or from the Controls Toolbox? The code that is used is different depending on how the ComboBox was created.

However, I would like to ask my question again, in a slightly different manner.

re: "One of the "hyperlinks" I'd like to change to a combo box so can "hyperlink" to the worksheet that the dropdown list value corresponds to."

Unless I am misunderstanding that sentence, using a Data Validation and the Worksheet_Change code I suggested would do just that. A drop down arrow would appear in a cell and the list would appear when the arrow was clicked. Once a worksheet name was chosen from the list, that name would appear in the same cell as the drop down arrow and the "change" would cause the Worksheet_Change code to run. The code would read the contents of the cell and activate the corresponding sheet - just like your ComboBox code is trying to do.

So once again, I ask (in a nice way!) Why do you need to use a ComboBox as opposed to a Data Validation Drop Down list?


0

Related Posts

See More



Response Number 6
Name: ipsquared
Date: August 1, 2007 at 17:20:59 Pacific
Reply:

DerbyDad03, Let me try what you say first, ie. data validation list. Then I'll try to better explain if doesn't work for some reason. BTW Thank you for taking the time to response so thoroughly. IPSquared


0

Response Number 7
Name: ipsquared
Date: August 1, 2007 at 17:49:15 Pacific
Reply:

DerbyDad03, Ok I tried a validation list and yes it definitely works, but it just doesn't have the desired appearance of a combobox. Also, when go back to worksheet where selected value on validation cell, it has the name of the last country selected. I'd like it to retain value cell label "Addresses" so can then select next "country" value. I know this sounds picky but this will be a tool used by others and I want to make it clear for them to use. I was originally using a combobox from the Forms not Control Toolbox on menu bar. Thanks, again


0

Response Number 8
Name: ipsquared
Date: August 1, 2007 at 18:45:23 Pacific
Reply:

FINALLY, got it working the way I wanted using combobox off Control Tool and my original code Thanks all for you help


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel combobox code

Excel combobox list value hyperlink www.computing.net/answers/office/excel-combobox-list-value-hyperlink/6856.html

Running excel VBA Code from a pre 2003 Macro www.computing.net/answers/office/running-excel-vba-code-from-a-pre-2003-macro/9591.html

Excel VBA code www.computing.net/answers/office/excel-vba-code/4587.html