I had attempted to code something in the same vein as for what's written for combobox1, but it's horrible code - brute force coding.
I'll show you what I've got below: what I'm trying to achieve here is for data sheets in certain columns, on the same sheet as combobox 1 and 2, to unhide based on the number of units selected in combobox 2, as well as the required certain costing sheet tabs to unhide based on combobox 2.
All seems to work ok (although I'd love to see the elegant concise code to replace this that I know is out there, somewhere) until I change the value in combobox 1 again, once I've changed combobox 2.
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ComboBox2_Change()<br>****<br>****<SPAN style="color:#00007F">Dim</SPAN> bWks <SPAN style="color:#00007F">As</SPAN> Worksheet, s <SPAN style="color:#00007F">As</SPAN> Shape, Alwayshidden <SPAN style="color:#00007F">As</SPAN> Range<br>********<SPAN style="color:#00007F">Set</SPAN> Alwayshidden = Range("i:l, X:AA")****** <SPAN style="color:#007F00">' Define the range to be permanently hidden</SPAN><br>****<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> bWks <SPAN style="color:#00007F">In</SPAN> ThisWorkbook.Worksheets<br>********<SPAN style="color:#00007F">If</SPAN> bWks.Name <> ComboBox1.Parent.Name <SPAN style="color:#00007F">Then</SPAN>**<SPAN style="color:#007F00">' don't hide the sheet with the combo box</SPAN><br>************<SPAN style="color:#00007F">If</SPAN> InStr(1, bWks.Name, "Thicknr") <SPAN style="color:#00007F">Then</SPAN><br>****************bWks.Visible = xlSheetVisible<br>************<SPAN style="color:#00007F">Else</SPAN><br>****************bWks.Visible = xlSheetHidden<br>************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>********<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****<SPAN style="color:#00007F">Next</SPAN> bWks<br>****<SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> ComboBox2.Text<br><br><SPAN style="color:#007F00">'**** Case "1" through "3" are as below, but with successively less nested if loops</SPAN><br><br>****** <SPAN style="color:#00007F">Case</SPAN> "4"<br>************<SPAN style="color:#00007F">Dim</SPAN> rngThickener4 <SPAN style="color:#00007F">As</SPAN> Range<br>************<SPAN style="color:#00007F">Set</SPAN> rngThickener4 = Range("AN:BF")<br>************<br>************Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>************************<br>************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> bWks <SPAN style="color:#00007F">In</SPAN> ThisWorkbook.Worksheets<br>****************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> ComboBox1.Parent.Name <SPAN style="color:#00007F">Then</SPAN>**<SPAN style="color:#007F00">' don't hide the sheet with the combo box</SPAN><br>********************<br>********************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> "Thicknr_1_Costing" <SPAN style="color:#00007F">Then</SPAN><br>************************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> "Thicknr_2_Costing" <SPAN style="color:#00007F">Then</SPAN><br>****************************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> "Thicknr_3_Costing" <SPAN style="color:#00007F">Then</SPAN><br>********************************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> "Thicknr_4_Costing" <SPAN style="color:#00007F">Then</SPAN><br>********************************bWks.Visible = xlSheetHidden<br>********************************<SPAN style="color:#00007F">Else</SPAN><br>********************************bWks.Visible = xlSheetVisible<br>********************************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****************************<SPAN style="color:#00007F">Else</SPAN><br>****************************bWks.Visible = xlSheetVisible<br>****************************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>************************<SPAN style="color:#00007F">Else</SPAN><br>************************bWks.Visible = xlSheetVisible<br>************************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>********************<SPAN style="color:#00007F">Else</SPAN><br>********************bWks.Visible = xlSheetVisible<br>********************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>************<SPAN style="color:#00007F">Next</SPAN> bWks<br>************<br>************Columns.Hidden = <SPAN style="color:#00007F">False</SPAN><br>************rngThickener4.EntireColumn.Hidden = <SPAN style="color:#00007F">True</SPAN><br>************Alwayshidden.EntireColumn.Hidden = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">' Hide the data validation selection columns</SPAN><br>************Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><br>********<SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN><br>******** <SPAN style="color:#00007F">Dim</SPAN> rngThickenerBlank <SPAN style="color:#00007F">As</SPAN> Range<br>************<SPAN style="color:#00007F">Set</SPAN> rngThickenerBlank = Range("R:BF")<br>******************<br>************Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>************<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> bWks <SPAN style="color:#00007F">In</SPAN> ThisWorkbook.Worksheets<br>****************<SPAN style="color:#00007F">If</SPAN> bWks.Name <> ComboBox1.Parent.Name <SPAN style="color:#00007F">Then</SPAN>**<SPAN style="color:#007F00">' don't hide the sheet with the combo box</SPAN><br>********************<br>********************<SPAN style="color:#00007F">If</SPAN> InStr(1, bWks.Name, "Thicknr_1") <SPAN style="color:#00007F">Then</SPAN><br>************************bWks.Visible = xlSheetVisible<br>************************<SPAN style="color:#00007F">Else</SPAN><br>************************bWks.Visible = xlSheetHidden<br>********************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>****************<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>************<br>************<SPAN style="color:#00007F">Next</SPAN> bWks<br>************<br>************Columns.Hidden = <SPAN style="color:#00007F">False</SPAN><br>************rngThickenerBlank.EntireColumn.Hidden = <SPAN style="color:#00007F">True</SPAN><br>************Alwayshidden.EntireColumn.Hidden = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">' Hide the data validation selection columns</SPAN><br>************Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>************<br>********<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN><br>********<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
Horrible - I know. Any suggestions on how to improve this (be kind, please!), as well as removing the Error 1004 I get in the situation described above?
Thanks