Sub Macro1()
'Step 1: Declare your variables
Dim ws As Worksheet
'Step 2: Start looping through all worksheets
For Each ws In ThisWorkbook.Worksheets
'Step 3: Check each worksheet name
If ws.Name <> ThisWorkbook.ActiveSheet.Name Then
'Step 4: Hide the sheet
ws.Visible = xlSheetHidden
End If
'Step 5: Loop to next worksheet
Next ws
End Sub
Sub SheetHidden()
Dim xWs As Worksheet
Dim xName As String
xName = Application.InputBox("Range", xTitleId, Application.ActiveSheet.Name, Type: = 2)
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> xName Then
xWs.Visible = xlSheetHidden
End If
Next
End Sub
for first code, after see it, i think i need it but i set a table from sheets in one sheet that each sheets linked to specific cell of table sheet, how going to this sheets when click on?This macro hides all sheets except active sheet.
and this one hide all except one that tell in InputBoxVBA Code:Sub Macro1() 'Step 1: Declare your variables Dim ws As Worksheet 'Step 2: Start looping through all worksheets For Each ws In ThisWorkbook.Worksheets 'Step 3: Check each worksheet name If ws.Name <> ThisWorkbook.ActiveSheet.Name Then 'Step 4: Hide the sheet ws.Visible = xlSheetHidden End If 'Step 5: Loop to next worksheet Next ws End Sub
VBA Code:Sub SheetHidden() Dim xWs As Worksheet Dim xName As String xName = Application.InputBox("Range", xTitleId, Application.ActiveSheet.Name, Type: = 2) For Each xWs In Application.ActiveWorkbook.Worksheets If xWs.Name <> xName Then xWs.Visible = xlSheetHidden End If Next End Sub
Private Sub Workbook_Open()
Dim oSheet As Excel.Worksheet
Dim oCmbBox As MSForms.ComboBox
Dim xWs As Worksheet
Dim xName As String
Set oCmbBox = ActiveWorkbook.Sheets(1).cmbSheet
oCmbBox.Clear
For Each oSheet In ActiveWorkbook.Sheets
oCmbBox.AddItem oSheet.Name
Next oSheet
End Sub
Private Sub cmbsheet_Change()
Dim xWs As Worksheet
Dim xName As String
Application.ScreenUpdating = False
For Each xWs In ThisWorkbook.Worksheets
xWs.Visible = True
Next
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> cmbSheet.Value And xWs.Name <> ThisWorkbook.ActiveSheet.Name Then
xWs.Visible = xlSheetHidden
End If
Next
Application.ScreenUpdating = True
End Sub
can you send a photo, i don't understand sorryOR
1st - Add a combobox into your first sheet and properly name it (I called it cmbSheet). I suggest to use an ActiveX Combobox (in Excel 2007, under Developer tab).
2nd - Open VBA and add the below code into your workbook code. This code will populate the combobox with the sheet names every time the workbook is opened.
VBA Code:Private Sub Workbook_Open() Dim oSheet As Excel.Worksheet Dim oCmbBox As MSForms.ComboBox Dim xWs As Worksheet Dim xName As String Set oCmbBox = ActiveWorkbook.Sheets(1).cmbSheet oCmbBox.Clear For Each oSheet In ActiveWorkbook.Sheets oCmbBox.AddItem oSheet.Name Next oSheet End Sub
3rd - Now, go to the code of your sheet (where the combobox has been added) and add the code that will activate the sheet chosen in the combobox & Active Sheet. The code is (Change cmbSheet to your combobox name, You see it when it add , right click, view code , Properties window, (Down-Left side of Vba window))
VBA Code:Private Sub cmbsheet_Change() Dim xWs As Worksheet Dim xName As String Application.ScreenUpdating = False For Each xWs In ThisWorkbook.Worksheets xWs.Visible = True Next For Each xWs In Application.ActiveWorkbook.Worksheets If xWs.Name <> cmbSheet.Value And xWs.Name <> ThisWorkbook.ActiveSheet.Name Then xWs.Visible = xlSheetHidden End If Next Application.ScreenUpdating = True End Sub
For this, can create two different code, one of them just unhide sheets number 1,2 and then unhide and another just unhide sheet number 3 and then unhide...this for second