Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
K K is offline
external usenet poster
 
Posts: 108
Default How do I set up macro in VBA to choose worksheets?

I want to set up a macro that will prompt me to select the name of a
worksheet (within a workbook) to view and then display that sheet.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default How do I set up macro in VBA to choose worksheets?

OK, here you go!
1. Create a user-form (UserForm1) in the VBA Editor.
2. On this user-form place a list-box (ListBox1) and two command-buttons
(CommandButton1 and CommandButton2).
3. Double-click on the user-form to open its code window and copy the
following code into it:

'-----------Code Start--------------
Private Sub CommandButton1_Click()
' This is going to be your Cancel button
'You may want to change its Caption property to Cancel
Unload Me
End Sub

Private Sub CommandButton2_Click()
' This is going to be your OK button
'You may want to change its Caption property to OK
On Error Resume Next
ThisWorkbook.Sheets(ListBox1.Text).Activate
Unload Me
End Sub

Private Sub UserForm_Initialize()
' This populates your list-box with available sheets names
For Each s In ThisWorkbook.Sheets
ListBox1.AddItem s.Name
Next s
End Sub
'-----------Code Finish--------------

4. In the Workbook module insert the following code:

'-----------Code Start--------------
Private Sub Workbook_Open()
UserForm1.Show
End Sub
'-----------Code Finish--------------

5. Save the file.

Regards,
KL

"K" wrote in message
...
I want to set up a macro that will prompt me to select the name of a
worksheet (within a workbook) to view and then display that sheet.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How do I set up macro in VBA to choose worksheets?

Take look at this earlier post http://tinyurl.com/6rqt2


--

HTH

RP
(remove nothere from the email address if mailing direct)


"K" wrote in message
...
I want to set up a macro that will prompt me to select the name of a
worksheet (within a workbook) to view and then display that sheet.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I set up macro in VBA to choose worksheets?


I used this method to create custom buttons for my workbook, but th
userform that displays the button choices appears infront of whateve
the last worksheet was that was open the last time the workbook wa
used. Is it possible to have the userform appear infront of a blan
page or screen when I open the workbook

--
alana
-----------------------------------------------------------------------
alanad's Profile: http://www.excelforum.com/member.php...fo&userid=1419
View this thread: http://www.excelforum.com/showthread.php?threadid=27581

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
choose table_array in VLOOKUP from list of multiple worksheets? LDP Analyst Excel Worksheet Functions 5 January 30th 08 12:56 PM
choose last specific nonblank cell from different worksheets Compassionate Felix Excel Discussion (Misc queries) 1 February 1st 07 07:07 PM
Set up macro in Excel to choose active row? kerri Excel Worksheet Functions 3 August 18th 06 01:44 AM
Help with macro to choose printer Wind54Surfer New Users to Excel 2 December 21st 04 12:09 AM
Choose Function Macro Jim[_31_] Excel Programming 2 April 14th 04 12:36 PM


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