Lumpy
Jul 21 2004, 04:56 PM
First of all, I am using a userform called userform2 to show a list of all the named sheets in my workbook, minus a few that I don't want included. The point being I get a nice list of Sheets and the user can then pick the ones that they want to delete. Here is the code.
Sub SheetsArray()
Dim I As Integer
Dim j As Integer
Dim SheetNameArray(99) As Variant
I = 1
j = 1
For Each sheetnow In Sheets
SheetName = sheetnow.Name
If SheetName = "A" Then GoTo SkipSheet
If SheetName = "TempPrint" Then GoTo SkipSheet
If SheetName = "Costing" Then GoTo SkipSheet
If SheetName = "Approval Form" Then GoTo SkipSheet
If SheetName = "Motor Template" Then GoTo SkipSheet
If SheetName = "Lookups" Then GoTo SkipSheet
If SheetName = "Sheet1" Then GoTo SkipSheet
SheetNameArray(I) = SheetName
I = I + 1
SheetNameArray(I - 1) = SheetNameArray(I - 1)
SkipSheet:
Next sheetnow
While j < I
userform2.ListBox1.AddItem SheetNameArray(j)
j = j + 1
Wend
userform2.Show
End Sub
Private Sub DelButton_Click()
userform2.Hide
End Sub
The Problem is, the DelButton_Click doesn't work.
When I click this button, I want the List box on the form to close and to return a list of all the items that were selected. Anyone know what I am doing wrong?
KingMartin
Jul 22 2004, 12:51 AM
Hi Eric,
Hide does not close the form, it just.. well, hides it.
Use Unload to close the form, eg
CODE
Private Sub DelButton_Click()
Unload Me
End Sub
Regards,
Martin
Lumpy
Jul 22 2004, 08:18 AM
Martin, Thanks for the help bu t this doesn't do it either. When I click on my delete button it does nothing. I have two buttons on the screen "Delete" and "Cancel". The point of the form is that the use can select from the available sheets, minus the certain ones, the sheets which they want to delete.
The first part of the code works well, I get a nice list box of all the available sheets that may be deleted. I simply cannot close the userform though. I am sure that I am doing something wrong, but I have gone through all of the properties for the button and the form as well as my code, and I cannot seem to find out what is going wrong.
KingMartin
Jul 22 2004, 09:34 AM
Hello again Eric,
maybe I missed the point. Have a look at the attached file if it's close to what you want.
M.
Lumpy
Jul 22 2004, 09:42 AM
Yep, That's it. Thanks Martin.
Lumpy
Aug 2 2004, 09:35 AM
Hey martin, I still can't get this to work. I have been through yours and it works beautifuly. But I still can't get mine to work. The only difference is that you are launching your userform2 from an embeded button and I am launching mine from a Custom drop down menu. Other than that I am using the exact same macros and I have checked the userform to make sure that everything is named correctly.
I have been over this six ways from Sunday and I still can't figure out what I am doing wrong! Let me know if you think of anything else.
Lumpy
Aug 2 2004, 09:56 AM
Hey Martin, Nevermind I guess that third cup of coffee shook it loose. I fixed it and it is running good. As always, thanks for the help and sorry if you put in extra effort from my last post.
KingMartin
Aug 2 2004, 10:03 AM
Actually I did not.

Glad you have it up 'n 'runnin'.

Martin
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.