Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default passing a comboxbox result into sheets.select

I have a form that has a combo box in it. The combo box allows the user to
select a chapter. The chapter happens to be worksheet in a workbook.

How do i pass from the combo box into the macro.

This is what I want:
With ComboBox8
.AddItem "Chapter 1"
.AddItem "Chapter 2"
.AddItem "Chapter 3"
End With
Chapter = ComboBox8.Value
Sheets(Chapter).Select

*** if I write Sheets("Chapter 1") it works great...but just putting it
Chapter fails



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default passing a comboxbox result into sheets.select

Where is this code, ou are only showing a snippet. The code below is using
the Form1_Initialize() event to load the items in the combobox and a button
on the form, hides it and selects the sheet from the combobox value.

Private Sub UserForm_Initialize()
With UserForm1.ComboBox8
.AddItem "Chapter 1"
.AddItem "Chapter 2"
.AddItem "Chapter 3"
End With
UserForm1.Show
End Sub

Private Sub CommandButton1_Click()
Dim Chapter As String
Chapter = UserForm1.ComboBox8.Value
UserForm1.Hide
Sheets(Chapter).Select
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"tbaam" wrote in message
...
I have a form that has a combo box in it. The combo box allows the user to
select a chapter. The chapter happens to be worksheet in a workbook.

How do i pass from the combo box into the macro.

This is what I want:
With ComboBox8
.AddItem "Chapter 1"
.AddItem "Chapter 2"
.AddItem "Chapter 3"
End With
Chapter = ComboBox8.Value
Sheets(Chapter).Select

*** if I write Sheets("Chapter 1") it works great...but just putting it
Chapter fails





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default passing a comboxbox result into sheets.select

The problem is that you are adding the items in the same
procedure as you are using to select the sheet.

Remove the following lines from you existing code

Chapter = ComboBox8.Value
Sheets(Chapter).Select

and insert the following code in the sheet's code module:

Private Sub ComboBox8_Change()
Dim Chapter As String
Chapter = Me.ComboBox8.Value
Worksheets(Chapter).Select
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"tbaam" wrote in message
...
I have a form that has a combo box in it. The combo box allows
the user to
select a chapter. The chapter happens to be worksheet in a
workbook.

How do i pass from the combo box into the macro.

This is what I want:
With ComboBox8
.AddItem "Chapter 1"
.AddItem "Chapter 2"
.AddItem "Chapter 3"
End With
Chapter = ComboBox8.Value
Sheets(Chapter).Select

*** if I write Sheets("Chapter 1") it works great...but just
putting it
Chapter fails





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default passing a comboxbox result into sheets.select

Try this:

'In the change event of your combobox
Private Sub ComboBox1_Change()

If Not Me.ComboBox1.Value = "" Then
Sheets(Me.ComboBox1.Value).Select
End If

End Sub

'To load sheet names when initializing the form
Private Sub UserForm_Initialize()

Dim s As Excel.Worksheet

For Each s In ThisWorkbook.Worksheets
Me.ComboBox1.AddItem s.Name
Next

End Sub

HTH.

- Luther

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default passing a comboxbox result into sheets.select

Thank you....i wasn't sure how much of the code I should put in the post...but
all of you answered my question.
It works great!

"lcifers" wrote:

Try this:

'In the change event of your combobox
Private Sub ComboBox1_Change()

If Not Me.ComboBox1.Value = "" Then
Sheets(Me.ComboBox1.Value).Select
End If

End Sub

'To load sheet names when initializing the form
Private Sub UserForm_Initialize()

Dim s As Excel.Worksheet

For Each s In ThisWorkbook.Worksheets
Me.ComboBox1.AddItem s.Name
Next

End Sub

HTH.

- Luther




Reply
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
ComboxBox with Dynamically Defined Source, and LinkedCell error GlennUK Excel Discussion (Misc queries) 1 June 4th 08 03:11 PM
passing values to other sheets [email protected] New Users to Excel 1 February 23rd 08 02:03 AM
Comboxbox in Commandbar Bhavtosh Excel Programming 3 January 20th 05 03:19 PM
Looping through Sheets and passing values to an Array Michael Rhein Excel Programming 2 February 13th 04 10:54 AM
Passing SQL Query Result Into A Variable Elliot[_2_] Excel Programming 4 January 9th 04 09:55 AM


All times are GMT +1. The time now is 07:06 AM.

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"