Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tac tac is offline
external usenet poster
 
Posts: 2
Default Problems with code

I am definitely new to this VBA world. I am trying to make a userform
listing all the sheets in a very large workbook so I can select on the name
listed. The result would be once the selection is made it would take me to
that sheet. This is the code I have so far....


Private Sub ListBox1_Click()
Sheet.Select
End Sub

Private Sub UserForm_Initialize()
For i = 1 To Sheets.Count
ListBox1.AddItem Sheets(i).Name
Next i
End Sub


What am I doing wrong?


Thanks Ted
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Problems with code

Ted,
You didn't provide enough information to Excel to be able to identify the sheet.
Also, it is good practice to use "Option Explicit" as the first line in every module.
It will force you to declare variables such as "i"
'------------------
'Hope you have a "Close" button on the form?
Private Sub CommandButton1_Click()
Me.Hide
Unload Me
End Sub

Private Sub ListBox1_Click()
Worksheets(ListBox1.Value).Select
End Sub

Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To Sheets.Count
ListBox1.AddItem Sheets(i).Name
Next 'i
End Sub
'----------------------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"tac"
wrote in message...
I am definitely new to this VBA world. I am trying to make a userform
listing all the sheets in a very large workbook so I can select on the name
listed. The result would be once the selection is made it would take me to
that sheet. This is the code I have so far....

Private Sub ListBox1_Click()
Sheet.Select
End Sub

Private Sub UserForm_Initialize()
For i = 1 To Sheets.Count
ListBox1.AddItem Sheets(i).Name
Next i
End Sub

What am I doing wrong?
Thanks Ted
  #3   Report Post  
Posted to microsoft.public.excel.programming
tac tac is offline
external usenet poster
 
Posts: 2
Default Problems with code

Jim:

Thanks for the help. Your suggestions for "good form" are greatly
appreciated.

Thanks Again

Ted

"Jim Cone" wrote:

Ted,
You didn't provide enough information to Excel to be able to identify the sheet.
Also, it is good practice to use "Option Explicit" as the first line in every module.
It will force you to declare variables such as "i"
'------------------
'Hope you have a "Close" button on the form?
Private Sub CommandButton1_Click()
Me.Hide
Unload Me
End Sub

Private Sub ListBox1_Click()
Worksheets(ListBox1.Value).Select
End Sub

Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To Sheets.Count
ListBox1.AddItem Sheets(i).Name
Next 'i
End Sub
'----------------------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"tac"
wrote in message...
I am definitely new to this VBA world. I am trying to make a userform
listing all the sheets in a very large workbook so I can select on the name
listed. The result would be once the selection is made it would take me to
that sheet. This is the code I have so far....

Private Sub ListBox1_Click()
Sheet.Select
End Sub

Private Sub UserForm_Initialize()
For i = 1 To Sheets.Count
ListBox1.AddItem Sheets(i).Name
Next i
End Sub

What am I doing wrong?
Thanks Ted

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
code with eomonth problems Gary Keramidas Excel Programming 4 March 3rd 06 03:15 AM
sorting code problems DKY[_10_] Excel Programming 2 September 24th 04 02:34 PM
Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Excel Programming 0 September 14th 04 02:58 PM
VBA Code problems! Simon Lloyd[_463_] Excel Programming 5 May 24th 04 10:21 PM
Loop code problems pauluk[_51_] Excel Programming 2 April 23rd 04 10:30 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"