MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 1st, 2002, 01:52 AM   #1
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

Hi,
I posted something similar yesterday,, but didn't seem to get it to work.

I've put a combo box in a user form, and want the selected item to jump to the worksheet that lives within the workbook.

Do I need to create a list of the worksheet names? (i.e London, West, East, Cardiff) or is it some kind of tricky DIM?

Thanks in advance...
Matt
mrowe is offline   Reply With Quote
Old May 1st, 2002, 02:13 AM   #2
Mr Nick
Board Regular
 
Join Date: Mar 2002
Location: Manchester, UK
Posts: 95
Default

Quote:
I've put a combo box in a user form, and want the selected item to jump to the worksheet that lives within the workbook.
Does the input from this box always go to the same position on the same worksheet, or does the insertion differ dependent on the input value?
Mr Nick is offline   Reply With Quote
Old May 1st, 2002, 02:22 AM   #3
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

Correct.

Basicly I have a user form called Utilities where I want the user to be able to select a worksheet from the drop down list (among other things). I've seen it before but don't know the code. The worksheets names won't change or be moved from a different location.

The reason for it all it a small solution for staff that are affraid of excel and want a point a click interface.

Cheers
Matt
mrowe is offline   Reply With Quote
Old May 1st, 2002, 02:30 AM   #4
Mr Nick
Board Regular
 
Join Date: Mar 2002
Location: Manchester, UK
Posts: 95
Default

If you are using a UserForm, then just attach the following code to the OK button on your form.

Private Sub CommandButton1_Click()
Sheets(ComboBox1.Text).Select
Unload UserForm1
End Sub
Mr Nick is offline   Reply With Quote
Old May 1st, 2002, 02:32 AM   #5
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

How do I populate the combo box with the sheet names?
mrowe is offline   Reply With Quote
Old May 1st, 2002, 02:37 AM   #6
Mr Nick
Board Regular
 
Join Date: Mar 2002
Location: Manchester, UK
Posts: 95
Default

If you set up a list of sheet names on one of your sheets e.g. Sheet1 cells A1 to A5, then on your userform, select the combobox and put =sheet1!a1:a5 in the RowSource property, you will see whatever you put in these cells in your dropdown.
Mr Nick is offline   Reply With Quote
Old May 1st, 2002, 02:39 AM   #7
mrowe
Board Regular
 
Join Date: Feb 2002
Posts: 232
Default

thanks for all your help.
Matt
mrowe is offline   Reply With Quote
Old May 1st, 2002, 02:51 AM   #8
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-01 00:52, mrowe wrote:
Hi,
I posted something similar yesterday,, but didn't seem to get it to work.

I've put a combo box in a user form, and want the selected item to jump to the worksheet that lives within the workbook.

Do I need to create a list of the worksheet names? (i.e London, West, East, Cardiff) or is it some kind of tricky DIM?

Thanks in advance...
Matt
Hi Matt...silly question BUT, can't the users
just click the worksheet tab to select the
sheet OR Right click on the Navigation keys
to the left of the sheet tabs and select
the sheet from the Popup Dialog Box ??

If you must have code to do this then you could try this routine;

1) It places a commandbutton in your main
excel commandbar
2) clicking this exercutes a routine that
dynamically creates a userform that
has a Combobox with the sheet names to
goto.
3 commandbuttons
GO , BACK , CANCEL

So that you Don't need to create a Userform

In the Thisworkbook object Place this code;


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Delete_Button
End Sub

Private Sub Workbook_Open()
Create_Button
End Sub



IN STD MODULE PLACE THIS CODE;


'// Discription: Creates a UserFrom on the fly
'// Userform contains Combobox and 3 buttons
'// ComboBox used to select via dropdown or typing,
'// The sheet to goto.
'// Buttons to Cancel, Goto sheet, Go back to last
'// selected sheet.

'// Userform is deleted after use.

'//Upon opening the file a button is created
'//that will call the creation of the form with it's
'//buttons.......Combobox had to be filled via
'//userform initialise ?? couldn't get it ??

'//Ivan F Moala 03 05 2001

'// Used to create a button to call the routine
'// So it can be used in any workbook that is open.

'//Code to go into a seperate Module;

'//This code handles the Back button, note
'//it is robust enough to handle or use for
'//any routine in which a return from is required.


Public Sub SaveLocation(ReturnToLoc As Boolean)

Static WB As Workbook
Static WS As Worksheet
Static Rg As Range

On Error GoTo NoGo
If ReturnToLoc = False Then
Set WB = ActiveWorkbook
Set WS = ActiveSheet
Set Rg = Selection
Else
WB.Activate
WS.Activate
Rg.Select
End If

Exit Sub
NoGo:
MsgBox "Can't DO...Not set !"
End Sub

'To save the current location, call SetSaveLoc.
Public Sub SetSaveLoc()
SaveLocation (False)
End Sub

'To return to the saved location, call GetSaveLoc.
Public Sub GetSaveLoc()
SaveLocation (True)
End Sub



IN ANOTHER MODULE PUT THIS CODE IN;


Option Explicit
'Routines to go into a seperate Module;
Option Base 1

'Passed back to the function from the UserForm
Public GETOPTION_RET_VAL As Variant

Function GetOption(Title)
Dim TempForm
Dim NewComboBox As MSForms.ComboBox
Dim NewCommandButton1 As MSForms.CommandButton
Dim NewCommandButton2 As MSForms.CommandButton
Dim NewCommandButton3 As MSForms.CommandButton
Dim X As Integer, TopPos As Integer
Dim MaxWidth As Long, Ams As String, Ap As String
Dim ShName()

' Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False

' Create the UserForm
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 300

' Add the ComBoBox
TopPos = 4
MaxWidth = 0 'Stores width of widest OptionButton
Set NewComboBox = TempForm.Designer.Controls.Add("forms.combobox.1")
With NewComboBox
.MatchEntry = fmMatchEntryFirstLetter
.Width = 200
.Height = 15
.Left = 8
.Top = TopPos
If .Width > MaxWidth Then MaxWidth = .Width
End With

' Add the Cancel button
Set NewCommandButton1 = TempForm.Designer.Controls.Add("forms.CommandButton.1")
With NewCommandButton1
.Caption = "Cancel"
.Height = 18
.Width = 44
.Left = MaxWidth + 12
.Top = 6
End With

' Add the GO button
Set NewCommandButton2 = TempForm.Designer.Controls.Add("forms.CommandButton.1")
With NewCommandButton2
.Caption = "GO"
.Height = 18
.Width = 44
.Left = MaxWidth + 12
.Top = 28
End With

' Add the Back button
Set NewCommandButton3 = TempForm.Designer.Controls.Add("forms.CommandButton.1")
With NewCommandButton3
.Caption = "< Back"
.Height = 18
.Width = 44
.Left = MaxWidth + 12
.Top = 50
End With

Ap = Chr(34): Ams = Chr(38)
' Add event-hander subs for the CommandButtons
With TempForm.CodeModule
X = .CountOfLines
.insertlines X + 0, "Option Base 1"

.insertlines X + 1, "Sub CommandButton1_Click()"
.insertlines X + 2, " GETOPTION_RET_VAL=False"
.insertlines X + 3, " Unload Me"
.insertlines X + 4, "End Sub"

.insertlines X + 5, "Sub CommandButton2_Click()"
.insertlines X + 6, " SetSaveloc"
.insertlines X + 7, " On Error Resume Next"
.insertlines X + 8, " Sheets(ComboBox1.Text).Activate"
.insertlines X + 9, " If Err.Number <> 0 Then MsgBox " & _
Ap & "Sheet " & Ap & Ams & " ComboBox1.Text " & Ams & Ap & " doesn't exists!"
.insertlines X + 10, "End Sub"

.insertlines X + 11, "Private Sub UserForm_Initialize()"
.insertlines X + 12, "Dim ShName(),X as Integer"
.insertlines X + 13, "ReDim ShName(Sheets.Count)"
.insertlines X + 14, "For X = 1 To Sheets.Count"
.insertlines X + 15, " ShName(X) = Sheets(X).Name"
.insertlines X + 16, "Next"
.insertlines X + 17, "ComboBox1.List() = ShName()"
.insertlines X + 18, "SetSaveLoc"
.insertlines X + 19, "End Sub"

.insertlines X + 20, "Sub CommandButton3_Click()"
.insertlines X + 21, "GetSaveLoc"
.insertlines X + 22, "End Sub"

End With

' Adjust the form
With TempForm
.Properties("Caption") = Title
.Properties("Width") = NewCommandButton1.Left + NewCommandButton1.Width + 10
If .Properties("Width") < 160 Then
.Properties("Width") = 160
NewCommandButton1.Left = 106
NewCommandButton2.Left = 106
End If
.Properties("Height") = 24 * 4 'no buttons + 1
End With

' Show the form
VBA.UserForms.Add(TempForm.Name).Show

' Delete the form
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=TempForm

' Pass the selected option back to the calling procedure
GetOption = GETOPTION_RET_VAL

End Function

Sub GotoSheet()
Dim UserChoice As Variant

UserChoice = GetOption("Select a Sheet")
If UserChoice = False Then End

End Sub

Sub Create_Button()
Dim TopButton As CommandBarButton
Set TopButton = Application.CommandBars(1).Controls.Add(Type:=msoControlButton, _
Before:=10)
With TopButton
.Style = msoButtonCaption
.Caption = "GoTo Sheet"
.OnAction = "GotoSheet"
End With
End Sub

Sub Delete_Button()
Application.CommandBars(1).Controls("GoTo Sheet").Delete
End Sub




__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:52 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes