Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 IfIf DropDown2.Value = "Norway" Then
Sheets("Norway").Select
End IfEnd Sub
Get runtime error 424 Object required message with line highlighted: If DropDown1.Value = "USA" Then Thankyou for any help!

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.

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

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!

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?

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

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

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

![]() |
![]() |
![]() |

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