unhide rows on sheet2 based on the values of checkboxes on sheet1 - excel

I have a workbook with three worksheets. On the first worksheet the user is asked to click "relevant" checkboxes that relate to their project. Based on these checkboxes one thing happens but on two worksheets:
On the first worksheet (same as checkboxes)
1. related rows appear when checked and disappear when not checked. This I have managed to figure out using the following code for each checkbox (I have 8 checkboxes):
Private Sub CheckBox1_Click()
[22:25].EntireRow.Hidden = Not CheckBox1
End Sub
On the second worksheet
2. Same as above but on a different sheet, I would like the same result of related rows appearing when checked and disappear when not checked. I am not sure how to refer to another worksheet, and / or if there is a way to insert another line to the above.
Any help is appreciated.

Related

Auto fit row height on other worksheets from a activex combobox

Firstly I cannot program in VBA but I know how useful it is. Secondly my Excel version is 2010 but the organisation has 365.
I have a project that is to be used to help a voluntary organisation in the UK comply with a new food labelling law. I have one in use but all line heights have to be adjusted manually with the risk that if not done some ingredients will not be stated.
The main sheet called View, it is for selecting a meal option in an activeX combobox drop down and via VLOOKUP's displaying a list of ingredients from the Data sheet. On the View sheet are also the buttons to run a number of print macros. Because of the very variable contents of each cell I need to reset row height after each selection, which I do on the View sheet as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("View").Select
Range("B3:B19").Select
Selection.Rows.AutoFit
End Sub
What I also need to do is reset row height on set ranges on other linked sheets as well. Linked to the View sheet are other sheets called Ingredients (which specifies what ingredients have to be used), Notice (headed A4 notice of all ingredients used) and Labels (same information as Notice but 6 to a page for takeaway food labels) which can be printed from the macro buttons. I have googled and found a number of suggested solutions, including this one:
AutoFit on rows that are referenced from different sheet using function - VBA
but for whatever reason I could not get any to work. Is there a way that I can get selected ranges of rows on the other sheets to work off of the Combobox change on the View sheet, either by modifying the above code or putting Private Subs into the other sheets? I have already tried using variations of the View code without success.
This is what worked thanks to CDP1802
Private Sub Worksheet_Change(ByVal Target As Range)
'To reset row heights on all printable sheets on selection in Combobox
Sheets("View").Rows("3:19").AutoFit
Sheets("Ingredients").Rows("5:22").AutoFit
Sheets("Notice").Rows("5:19").AutoFit
Sheets("Labels").Rows("1:39").AutoFit
End Sub

On selecting a checkbox in excel the "Tab(s)" should get enabled/disabled or Appear/disappear

Can someone help me with the VBA code
On clicking a checkbox in excel the "Tab(s)" should get enabled/disabled or Appear/disappear
For eg. There is a tab name"Summary" and in Summary sheet1 I have a checkbox. On selecting the checkbox in the sheet1, the sheet 2 should get enabled/disabled or it should appear or disappear
Your help would be much appreciated
Paste this procedure in the code sheet of the worksheet on which you have the CheckBox, for example your Summary sheet.
Private Sub CheckBox1_Click()
Worksheets("Sheet2").Visible = IIf(CheckBox1.Value, xlSheetHidden, xlSheetVisible)
End Sub
There are two references to CheckBox1. That's the name of the check box - in the sub's declaration and the code. If it has another name change both references. Change the name of the worksheet you wish to hide. If you have several check boxes on your worksheet place identical procedures in the code sheet, each referring to another check box.
Note that there are two different kinds of hiding a sheet, xlSheetHidden and xlSheetVeryHidden. Both remove the tab from the bar below the Excel window. However, if you use xlSheetHidden the hidden worksheet can be shown by selecting Unhide from the Format Cells menu. If you choose xlSheetVeryHidden the sheet will not be listed there and the only way to show it again is by access to the VB Editor or code.

Getting Values from Multiple Comboxes in same sub

I have an excel sheet workbook with 2 sheets. One sheet has data imported from an external source and the other sheet then filters this data. I want to be able to select a date range to narrow done the filtered results.
To do this, I have 4 comboboxes, one checkbox, and one button. When the button is clicked I want my sub to first see if the checkbox has been checked. If it has not, then just run filter the data regardless of date. If the checkbox is checked, I then want to look at the four comboboxes. The first two will have the start year and start month and the last two will have the end year and end month. I want to take these values and filter my data using this criteria as well when the checkbox has been checked.
The issue I am having is that I cannot get the value of the combobox. For example, I named one of my comboboxes "Start_Month". In my sub, when I select the sheet with the combobox first, then I use "Start_Month.Value" to check the combobox value, but this gives me runtime error 424 "Object Required".
Does anybody know how to get the value of four different comboboxes in the same sub or is this not possible?

Excel graphical glitches when moving between sheets with private subs?

I encountered an odd graphical glitch when running private subs on a sheet then using a macro to jump to another sheet with a private sub on it. Basically excel is getting slowed down (the drop down menu's in the ribbons get messed up as well).
IE:
Sheet 1 has
Private Sub Worksheet_Deactivate()
Sheets("Sheet1").Visible = False
End Sub
Sheet 2 has the above code as well except Sheet2 would be the one made hidden when deactivating the worksheet.
With a button placed on sheet1 which trigger the following macro
Sub Sheet1_Button1_Click()
Sheets("Sheet2").Visible = True
Sheets("Sheet2").Select
End Sub
For testing purposes I was just using another macro assigned button on sheet2 that jumped back to sheet one and found that caused the issue. Does anyone know what's going on here and how to prevent it? Maybe this is more of a Microsoft issue?
In my original workbook I had a private sub on a "Cost Estimations" sheet that would run some some code to un-hide used lines and re-hide unused lines in a table that was referencing another sheet. Then I had a macro assigned button on that same sheet that would open a normally hidden sheet with some more info on it. The "hidden" sheet had a private sub on it that automatically hide it when the user clicks off of the sheet just like the "Sheet1" in my example. Additionally in the original workbook it was causing all the information from "cost estimations" to display on the "hidden" sheet, but only if calculations were set to automatic. I was however unable to replicate that in my test worksheet.

Capture cell value on worksheet when user right clicks a tab and deletes?

Been searching but cannot find any reference to what I am trying to accomplish.
Background
I use a worksheet (worksheer#2) to enter certain data for an aircraft model. When the data is correct I run a macro to copy that data into another worksheet and rename the cipued one with the aircraft name. I do this for as many aircraft as i need. All created sheets are all placed between two other blank sheets named Start and End.
I can manipulate any specific worksheet by name using buttons on worksheet #2 perfectly and when the macro runs it updates relevant cells on worksheet#2 accordingly.
Those values are required elsewhere in my workbook and have to be correct. That all works fine but it all falls over when the worksheet is deleted/moved by way of right clicking the worksheet tab and then deleteing or holding and dragging the sheet to another location.
Is there a way to capture the worksheet name when it is manipulated in this fashion so I can use the info to update data on worksheet #2 with?
There is a worksheet-level event called BeforeDelete.
Right click on the tab and choose View Code
In the General drop-down at the top-left of the VBA Editor, choose ``WorkSheet" and in the (Declarations) drop down at top-right, choose BeforeDelete.
This will create an empty procedure where you can add your code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
More Information:
Worksheet.BeforeDelete Event (Excel)

Resources