Generate sheet by running macro through hidden sheets

Cycs1516

New Member
Joined
Feb 20, 2018
Messages
3
Hello peeps,

I need some help here. When the COMMS & GO box are checked, and I click on Generate Form, it will move to the "COMMSGO" Sheet. I manage to do until here. But however, I just it to show only the "COMMSGO" sheet and the rest hidden. Same goes if i do it for other sheets. How do I run macro on the hidden sheets if I hide it, and only appear the sheet that I want when the "Generate Form" is pressed. I have searched through the forum, but I didnt manage to find any solution.

Help is much appreciated and thank you!

11j2jqc.jpg
[/IMG]


My formula is as below.

Code:
Sub SelectSheet1()
Dim sheetName As String
If CheckBox1.Value = True Then sheetName = Range("B6").Value
If CheckBox2.Value = True Then sheetName = sheetName & Range("B7").Value
If CheckBox3.Value = True Then sheetName = sheetName & Range("B8").Value
If CheckBox4.Value = True Then sheetName = sheetName & Range("B9").Value
Worksheets(sheetName).Select
End Sub

Sub SelectSheet2()
Dim sheetName As String
If CheckBox1.Value = False Then
If CheckBox2.Value = True Then sheetName = Range("B7").Value
If CheckBox3.Value = True Then sheetName = sheetName & Range("B8").Value
If CheckBox4.Value = True Then sheetName = sheetName & Range("B9").Value
Worksheets(sheetName).Select
End If
End Sub

Sub SelectSheet3()
Dim sheetName As String
If CheckBox1.Value = False Then
If CheckBox2.Value = False Then
If CheckBox3.Value = True Then sheetName = Range("B8").Value
If CheckBox4.Value = True Then sheetName = sheetName & Range("B9").Value
Worksheets(sheetName).Select
End If
End If
End Sub

Sub SelectSheet4()
Dim sheetName As String
If CheckBox1.Value = False Then
If CheckBox2.Value = False Then
If CheckBox3.Value = False Then
If CheckBox4.Value = True Then sheetName = Range("B9").Value
Worksheets(sheetName).Select
End If
End If
End If
End Sub

Sub SelectSheet5()
Dim sheetName As String
If CheckBox1.Value = True Then sheetName = Range("B6").Value
If CheckBox2.Value = False Then
If CheckBox3.Value = False Then
If CheckBox4.Value = True Then sheetName = sheetName & Range("B9")
Worksheets(sheetName).Select
End If
End If
End Sub

Sub RunAll()
Call SelectSheet1
Call SelectSheet2
Call SelectSheet3
Call SelectSheet4
Call SelectSheet5
End Sub
 
Last edited by a moderator:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi & welcome to MrExcel
How about
Code:
Sub SelectSht()

   Dim ShtNm As String
   Dim Ws As Worksheet
   Dim Cnt As Long
   Dim cbx As OLEObject
   
   For Each Ws In Worksheets
      If Ws.Name <> "Generate Form" Then Ws.Visible = xlSheetHidden
   Next Ws
   Cnt = 5
   For Each cbx In ActiveSheet.OLEObjects
      If TypeName(cbx.Object) = "CheckBox" Then
         Cnt = Cnt + 1
         If cbx.Object = True Then ShtNm = ShtNm & Range("B" & Cnt).Value
      End If
   Next cbx
   With Sheets(ShtNm)
      .Visible = True
      .Activate
   End With
End Sub
This replaces all your code & assumes that you are using ActiveX checkboxes
 
Upvote 0
Omg, thanks fluff, it worked perfectly. But is there anyway to hide the "Generate Form" Tab also after generating. Many thanks!
 
Upvote 0
Just add this
Code:
   Sheets("Generate Form").Visible = xlSheetHidden
Before the End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top