Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 32
Default Let User Select Sheet to Pull Data From

I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons, whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Let User Select Sheet to Pull Data From

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox and
command button. Right click on UserForm1 iconView Code and paste the below
code in the code section. Press F5 to initiate the forma which will list down
all sheets in the combo box..Now you can have your code placed in command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons, whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 32
Default Let User Select Sheet to Pull Data From

Jacob, thanks, I have followed your instructions. How do I link the Command
Button to the Combo Box? In the Command Button, where I would normally have
"Sheets("2").Select", do I just delete those lines of code because the
Command Button is going to automatically go to the sheet selected in the
Combo Box?

My code goes back and forth between Sheet 1 and Sheet 2 to draw in different
sections of data so I don't overwrite some things that are in Sheet 1. How
do I bring in the data from Sheet 2 in several different steps? For example,
Step 1 is to copy in Columns B-D, and Step 2 is to copy in Columns G-H
(omitting Columns E-F because those Columns in Sheet 1 can't be overwritten)?

"Jacob Skaria" wrote:

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox and
command button. Right click on UserForm1 iconView Code and paste the below
code in the code section. Press F5 to initiate the forma which will list down
all sheets in the combo box..Now you can have your code placed in command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons, whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 32
Default Let User Select Sheet to Pull Data From

And this is a silly question but I've never created the Combo Box using F11
before. How do I get the Combo Box onto Sheet 1?

"Jacob Skaria" wrote:

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox and
command button. Right click on UserForm1 iconView Code and paste the below
code in the code section. Press F5 to initiate the forma which will list down
all sheets in the combo box..Now you can have your code placed in command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons, whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 32
Default Let User Select Sheet to Pull Data From

I figured out how to bring up the Userform by using a command button.

I still need help understanding how to link the Control Box drop-down sheet
selected to the code that pulls in the data from the selected sheet.

Whenever I select an item from the Combo Box, it reverts to the first sheet.
It won't actually select the sheet that I am choosing.

"opieandy" wrote:

And this is a silly question but I've never created the Combo Box using F11
before. How do I get the Combo Box onto Sheet 1?

"Jacob Skaria" wrote:

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox and
command button. Right click on UserForm1 iconView Code and paste the below
code in the code section. Press F5 to initiate the forma which will list down
all sheets in the combo box..Now you can have your code placed in command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons, whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,494
Default Let User Select Sheet to Pull Data From

do you want a userform or a combobox on sheet 1?

--

Gary Keramidas
Excel 2003


"opieandy" wrote in message
...
I figured out how to bring up the Userform by using a command button.

I still need help understanding how to link the Control Box drop-down
sheet
selected to the code that pulls in the data from the selected sheet.

Whenever I select an item from the Combo Box, it reverts to the first
sheet.
It won't actually select the sheet that I am choosing.

"opieandy" wrote:

And this is a silly question but I've never created the Combo Box using
F11
before. How do I get the Combo Box onto Sheet 1?

"Jacob Skaria" wrote:

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox
and
command button. Right click on UserForm1 iconView Code and paste the
below
code in the code section. Press F5 to initiate the forma which will
list down
all sheets in the combo box..Now you can have your code placed in
command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows.
Each
sheet has the statistics of a baseball team in a standard format
(Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is
that for
each button, I have to have a set of code that is exactly the same,
with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make
to the
code, I have to make it to all 20 code sections. Further, I am
expanding
this file to include hundreds of sheets and don't to copy and paste
code
every time, or have to change hundreds of sections for a single
common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons,
whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from
the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls
in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1
set of
code and variable sheet names that code can pull data from?

Thanks!

Chris


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,494
Default Let User Select Sheet to Pull Data From

make yourself a userform with 1 combobox on it
right click the form in the project explorer window
paste this code and then run the form

Private Sub ComboBox1_Change()
Worksheets(ComboBox1.Value).Select
End Sub

Private Sub UserForm_Initialize()
Dim i As Long

For i = 1 To Worksheets.Count
With Me.ComboBox1
.AddItem Worksheets(i).Name
End With
Next
End Sub


--

Gary Keramidas
Excel 2003


"opieandy" wrote in message
...
I figured out how to bring up the Userform by using a command button.

I still need help understanding how to link the Control Box drop-down
sheet
selected to the code that pulls in the data from the selected sheet.

Whenever I select an item from the Combo Box, it reverts to the first
sheet.
It won't actually select the sheet that I am choosing.

"opieandy" wrote:

And this is a silly question but I've never created the Combo Box using
F11
before. How do I get the Combo Box onto Sheet 1?

"Jacob Skaria" wrote:

Launch VBE using Alt+F11. From menuInsertUserform. Place a combobox
and
command button. Right click on UserForm1 iconView Code and paste the
below
code in the code section. Press F5 to initiate the forma which will
list down
all sheets in the combo box..Now you can have your code placed in
command
button to pull information from the selected sheet..

Private Sub UserForm_Activate()
For Each shTemp In ThisWorkbook.Sheets
Me.ComboBox1.AddItem shTemp.Name
Next
Me.ComboBox1.ListIndex = 0
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"opieandy" wrote:

I have 20 sheets that all have a standard set of columns and rows.
Each
sheet has the statistics of a baseball team in a standard format
(Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is
that for
each button, I have to have a set of code that is exactly the same,
with the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make
to the
code, I have to make it to all 20 code sections. Further, I am
expanding
this file to include hundreds of sheets and don't to copy and paste
code
every time, or have to change hundreds of sections for a single
common edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons,
whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from
the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls
in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1
set of
code and variable sheet names that code can pull data from?

Thanks!

Chris


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,494
Default Let User Select Sheet to Pull Data From

you can try to adapt this. i used a combobox named drop down 1. change to
suit your worksheet.
then right click the combobox and assign the 2nd macro
run the first macro to clear and populate the list box.

then selecting the sheet from the drown should take you to the sheet.

Sub Fill_DropDown()
Dim dDown As Object
Set dDown = Worksheets("Sheet1").DropDowns("Drop Down 1")
dDown.RemoveAllItems

For i = 1 To Worksheets.Count
dDown.AddItem Worksheets(i).Name
Next
End Sub



Sub Select_Sheet()
Dim dDown As Object
Set dDown = Worksheets("Sheet1").DropDowns("Drop Down 1")
Worksheets(dDown).Select
End Sub


--

Gary Keramidas
Excel 2003


"opieandy" wrote in message
...
I have 20 sheets that all have a standard set of columns and rows. Each
sheet has the statistics of a baseball team in a standard format (Games,
At-Bats, Hits, etc., all exactly the same columns on each sheet.)

On Sheet 1 preceding these 20 sheets, I want the user to select the
desired team from a list and have Sheet 1 pull in the stats from the
applicable team's stat sheet. So my file looks like this:

Sheet 1 - Main Sheet for User Input and Presenting Desired Data
Sheet 2 - Atlanta Braves stats
Sheet 3 - Boston Red Sox stats
Sheet 4 - NY Yankees stats
Sheets 5-20... - more individual team stats like sheets 2-4

I have designed this in VBA using option buttons. The problem is that for
each button, I have to have a set of code that is exactly the same, with
the
only difference being the sheet name that is being referred to.

This is inefficient because when I identify a change I want to make to the
code, I have to make it to all 20 code sections. Further, I am expanding
this file to include hundreds of sheets and don't to copy and paste code
every time, or have to change hundreds of sections for a single common
edit I
make to the code.

I would like to have a single code section, with the sheet name as a
variable the user selects (from a drop-down list, set of buttons,
whatever).

Let's say it's a drop-down list. The user selects "NY Yankees" from the
drop-down list. The VBA code goes to the NY Yankees sheet and pulls in a
range of data into Sheet 1.

How do I get VBA to allow for user input of a sheet so I can have 1 set of
code and variable sheet names that code can pull data from?

Thanks!

Chris


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
Pull Data from one sheet to another Dax Arroway Excel Worksheet Functions 1 November 20th 08 02:44 AM
How do I use a formula on wk sheet 2 to pull data from wk sheet 1 WFG3000 Excel Discussion (Misc queries) 1 December 13th 07 06:58 AM
Pull user-specified rows from data set DoooWhat Excel Discussion (Misc queries) 7 February 27th 07 03:36 PM
How can I pull data from multiple user workbooks into one? Stuart Peters Excel Discussion (Misc queries) 4 April 8th 06 11:29 AM
pull data from sheet two, then fill in the data to sheet one (part Jim Excel Worksheet Functions 3 December 11th 04 04:51 AM


All times are GMT +1. The time now is 03:48 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"