Vous êtes sur la page 1sur 2

D's answer will unhide every sheet that is hidden. If you are wanting to unhide everything.

That is the easiest way. However if you are wanting to not unhide ev erything and just unhide several particular ones that you want, then you need to get a little more sophisticated in the macro programming. Here's how you can do that: You're going to need to create a new form in Visual Basic Editor. I called mine UserForm1. Then on that form you are going to need to create a listbox. I called mine ListBox1. Then you are going to need to create a command button. I called mine CommandButton1. Select the listbox on the form and go to the MultiSelect pr operty in the Properties Window. If you don't see the properties window, then go to View > Properties Window in Visual Basic Editor. Change MultiSelect from its default value of 0 to a value of 1. This allows you to select multiple lines in your listbox. Now right click the form and select View Code. Above the code win dow are two drop down combo boxes. Change the right one from Click to Activate a nd paste in the following between the lines of code that were just created: Dim i As Integer ListBox1.Clear For i = 1 To Sheets.Count If Sheets(i).Visible = False Then ListBox1.AddItem Sheets(i).Name End If Next i It should look like this when you are done: Private Sub UserForm_Activate() Dim i As Integer ListBox1.Clear For i = 1 To Sheets.Count If Sheets(i).Visible = False Then ListBox1.AddItem Sheets(i).Name End If Next i End Sub That code will populate the listbox with the list of hidden sheets in the workbo ok. Now go to change the left drop down combo to CommandButton1 and the right one to Click. Then paste the following between the two lines of code: For x = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(x) Then Sheets(ListBox1.List(x)).Visible = True End If Next x UserForm1.Hide It should look like this when you are done: Private Sub CommandButton1_Click() For x = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(x) Then Sheets(ListBox1.List(x)).Visible = True End If Next x UserForm1.Hide

End Sub That code tells Excel to unhide the sheets that you selected. Now there is only one thing more that you need to do. You need to create a macro to show UserForm1. So go to Insert > Module and insert a new module. Then paste the following: Sub UnHideAll() UserForm1.Show End Sub Now all you have to do is go to Tools > Macro > Macros... then select the UnHide All macro and run it. Then you can use the form to unhide your worksheets. What I usually do is I copy the forms and the macro code over to the Personal ma cro workbook then I create a new icon in excel to a custom menu bar and assign t he macro (UnHideAll) to the new icon. This sets it up so that whenever I click t he icon, the form will show so I can easily unhide the worksheets.

Vous aimerez peut-être aussi