Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default MultiSelect Listbox Question

Trying to add (create) worksheets in a workbook using a MultiSelect Listbox and have the sheet tabs be names as selected in the MultiSelect Listbox.

It has me stumped. I have been able to delete sheets and even print sheets, using a MultiSelect Listbox. The difference is deleting and printing the sheets exist.

Any help would be appreciated.

Thank you in advance.

WKWells

--
Posted by Mimo Usenet Browser v0.2.5
http://www.mimousenet.com/mimo/post


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default MultiSelect Listbox Question


"wkwells" wrote in message Trying to add (create)
worksheets in a workbook using a MultiSelect Listbox and have the sheet tabs
be names as selected in the MultiSelect Listbox.

It has me stumped. I have been able to delete sheets and even print
sheets, using a MultiSelect Listbox. The difference is deleting and
printing the sheets exist.

Any help would be appreciated.

Thank you in advance.

WKWells


Adapt the following

'with a listbox and a commanbutton on the form

Private Sub CommandButton1_Click()
Dim i
Dim sName As String
Dim sht As Object
Dim ws As Worksheet

For i = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.Selected(i) Then
sName = Me.ListBox1.List(i)
On Error Resume Next
Set sht = ActiveWorkbook.Sheets(sName)
On Error GoTo 0

If Not sht Is Nothing Then
MsgBox sName & " already exists"

Else
Set ws = ActiveWorkbook.Worksheets.Add
ws.Name = sName
End If

Me.ListBox1.RemoveItem i

End If
Next
ListBox1_Change
End Sub

Private Sub ListBox1_Change()

Me.CommandButton1.Enabled = Me.ListBox1.ListIndex = 0

End Sub

Private Sub UserForm_Initialize()
Dim i As Long
Dim arr
Dim sht As Object

arr = Array("Apples", "Bananas", "Pears", "Oranges")
Me.ListBox1.List = arr
For i = UBound(arr) To i Step -1
For Each sht In ActiveWorkbook.Sheets
If LCase$(sht.Name) = LCase$(arr(i)) Then
Me.ListBox1.RemoveItem i
Exit For
End If
Next
Next
Me.CommandButton1.Enabled = False
Me.CommandButton1.Caption = "Add selected sheet(s)"

End Sub

Regards,
Peter T


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
MultiSelect ListBox Help VBA_Newbie79[_2_] Excel Programming 2 June 29th 07 07:28 PM
How do I use a multiselect listbox Neil Murphy Excel Programming 2 November 17th 06 10:00 AM
Multiselect Listbox Francis Ang[_3_] Excel Programming 0 October 27th 04 02:21 AM
Multiselect listbox selection question Paul Mueller Excel Programming 3 June 16th 04 09:25 PM
multiselect listbox CG Rosén Excel Programming 2 December 28th 03 05:17 PM


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