VBAs in excel for beginners!

%3CLINGO-SUB%20id%3D%22lingo-sub-1497896%22%20slang%3D%22en-US%22%3EVBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1497896%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20have%20a%20basic%20checklist%20with%20drop%20down%20lists%20of%20yes%2C%20no%20or%20n%2Fa.%20For%20certain%20question%20if%20you%20select%20no%20you%20can%20skip%20down%20to%20a%20lower%20section%20and%20miss%20out%20some%20questions%20but%20to%20make%20the%20form%20more%20user%20friendly%20I'd%20like%20to%20hid%20the%20rows%20that%20aren't%20required.%20I%20have%20manage%20to%20do%20this%20for%20the%20first%20question%20however%20how%20do%20I%20add%20multiple%20commands%20for%20further%20questions%3F%20Here's%20what%20I%20have%20got%20for%20the%20first%20question%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EIf%20Range(%22E5%22)%20%3D%20%22No%22%20Then%3CBR%20%2F%3ERows(%226%3A45%22).EntireRow.Hidden%20%3D%20True%3CBR%20%2F%3EElse%3CBR%20%2F%3ERows(%226%3A45%22).EntireRow.Hidden%20%3D%20False%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20copied%20this%20command%20from%20a%20tutorial%20and%20changed%20the%20values%20but%20don't%20fully%20understand%20how%20the%20function%20works!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1497896%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1498071%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1498071%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714088%22%20target%3D%22_blank%22%3E%40North_Yorks%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20repeat%20the%20code%20from%20%3CSTRONG%3EIf%3C%2FSTRONG%3E%20to%20%3CSTRONG%3EEnd%20if%20%2C%3C%2FSTRONG%3E%20though%20with%20a%20different%20cell%20to%20check%20and%20different%20rows%20to%20hide%20or%20unhide.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1501511%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1501511%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHi%2C%20thanks%20I've%20added%20them%20all%20but%20the%20first%20rule%20is%20not%20working%20it%20only%20hides%203%20rows%20to%20the%20next%20rule%20when%20it%20should%20hide%20all%20questions%20to%20line%2045%20-%20all%20other%20rules%20are%20working%20correctly.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Range(%22E5%22)%20%3D%20%22No%22%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%226%3A45%22).EntireRow.Hidden%20%3D%20True%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%226%3A45%22).EntireRow.Hidden%20%3D%20False%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Range(%22E7%22)%20%3D%20%22No%22%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%228%3A18%22).EntireRow.Hidden%20%3D%20True%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%228%3A18%22).EntireRow.Hidden%20%3D%20False%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Range(%22E20%22)%20%3D%20%22No%22%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2221%3A24%22).EntireRow.Hidden%20%3D%20True%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2221%3A24%22).EntireRow.Hidden%20%3D%20False%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Range(%22E26%22)%20%3D%20%22No%22%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2227%3A36%22).EntireRow.Hidden%20%3D%20True%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2227%3A36%22).EntireRow.Hidden%20%3D%20False%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20Range(%22E38%22)%20%3D%20%22No%22%20Then%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2239%3A45%22).EntireRow.Hidden%20%3D%20True%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EElse%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ERows(%2239%3A45%22).EntireRow.Hidden%20%3D%20False%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20If%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20Sub%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1501637%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1501637%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714088%22%20target%3D%22_blank%22%3E%40North_Yorks%3C%2FA%3E%26nbsp%3BInsert%20%22Exit%20Sub%22%20before%20the%20first%20%22Else%22.%20Then%20it%20works.%20When%20E5%20%3D%20No%2C%20you%20want%20to%20hide%20all.%20No%20need%20to%20check%20any%20further.%20Without%20the%20exit%20code%2C%20the%20macro%20check%20the%20next%20condition.%20It%20is%20not%20No%2C%20thus%20it%20unhides%20the%20rows%20that%20were%20hidden%20in%20the%20first%20step%20and%20so%20on.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%0AIf%20Range(%22E5%22)%20%3D%20%22No%22%20Then%0ARows(%226%3A45%22).EntireRow.Hidden%20%3D%20True%0AExit%20Sub%0AElse%0ARows(%226%3A45%22).EntireRow.Hidden%20%3D%20False%0AEnd%20If%0A%0AIf%20Range(%22E7%22)%20%3D%20%22No%22%20Then%0ARows(%228%3A18%22).EntireRow.Hidden%20%3D%20True%0AElse%0ARows(%228%3A18%22).EntireRow.Hidden%20%3D%20False%0AEnd%20If%0A%0AIf%20Range(%22E20%22)%20%3D%20%22No%22%20Then%0ARows(%2221%3A24%22).EntireRow.Hidden%20%3D%20True%0AElse%0ARows(%2221%3A24%22).EntireRow.Hidden%20%3D%20False%0AEnd%20If%0A%0AIf%20Range(%22E26%22)%20%3D%20%22No%22%20Then%0ARows(%2227%3A36%22).EntireRow.Hidden%20%3D%20True%0AElse%0ARows(%2227%3A36%22).EntireRow.Hidden%20%3D%20False%0AEnd%20If%0A%0AIf%20Range(%22E38%22)%20%3D%20%22No%22%20Then%0ARows(%2239%3A45%22).EntireRow.Hidden%20%3D%20True%0AElse%0ARows(%2239%3A45%22).EntireRow.Hidden%20%3D%20False%0AEnd%20If%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1501743%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1501743%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%20Thank%20you%20it%20now%20works%20perfectly!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1501811%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1501811%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714088%22%20target%3D%22_blank%22%3E%40North_Yorks%3C%2FA%3E%26nbsp%3BGreat!%20Glad%20I%20could%20help%20solving%20your%20problem.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1505151%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505151%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3Bspreadsheet%20it%20still%20working%20perfectly%20but%20there%20is%20a%20'nice-ity'%20we'd%20like%20if%20it%20is%20at%20all%20possible%20to%20do!%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20have%20it%2C%20so%20when%20you%20open%20the%20document%20all%20the%20questions%20are%20collapsed%20-%20as%20if%20you%20have%20selected%20no%20for%20each%2C%20but%20without%20having%20'no'%20typed%2Fselected%20in%20them%3F%20But%20still%20have%20the%20options%20to%20select%20no%20yes%20n%2Fa%20in%20the%20drop%20down%20lists%20I%20already%20have%3F%3C%2FP%3E%3CP%3EAs%20I%20said%20its%20not%20a%20necessity%20but%20a%20nice%20to%20have!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%20in%20advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1505157%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505157%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714088%22%20target%3D%22_blank%22%3E%40North_Yorks%3C%2FA%3E%26nbsp%3BYou%20could%20paste%20the%20following%20code%20into%20the%20code%20window%20for%20the%20%22Thisworkbook%22%20tab%20in%20the%20VB%20editor%2C%20similar%20to%20how%20you%20pasted%20the%20other%20code%20into%20the%20Sheet1%20code%20window.%20See%20if%20you%20can%20get%20it%20to%20work%20in%20your%20real%20workbook.%20It%20worked%20on%20my%20end.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20Workbook_Open()%0A%0ARows(%228%3A18%22).EntireRow.Hidden%20%3D%20True%0ARows(%2221%3A24%22).EntireRow.Hidden%20%3D%20True%0ARows(%2227%3A36%22).EntireRow.Hidden%20%3D%20True%0ARows(%2239%3A45%22).EntireRow.Hidden%20%3D%20True%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1518271%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1518271%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3BHi%2C%20this%20worked%20great%20for%20my%20first%20worksheet%20but%20I%20have%202%20more%20and%20they%20have%20a%20different%20amount%20of%20questions%20so%20different%20amount%20of%20rows%20need%20to%20be%20collapsed.%20Would%20I%20just%20copy%20the%20said%20command%20but%20specify%20which%20worksheet%20and%20which%20lines%3F%20How%20would%20I%20specify%20which%20worksheet%3F%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1518341%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1518341%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F714088%22%20target%3D%22_blank%22%3E%40North_Yorks%3C%2FA%3E%26nbsp%3BSee%20attached%20file%20with%20my%20original%20code%20in%20it.%20Three%20sheets%2C%20all%20with%20the%20same%20set-up%2C%20just%20for%20testing%20purposes.%20I%20believe%20it%20works%20as%20you%20want%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20code%20for%20%22Thisworkbook%22%2C%20add%20a%20line%20that%20activates%20each%20sheet%20before%20you%20specify%20which%20rows%20to%20hide%20in%20it%20upon%20opening%20the%20workbook%2C%20similar%20to%20this%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESheets(%22Sheet1%22).Activate%0A%3CCODE%20for%3D%22%22%20hiding%3D%22%22%20rows%3D%22%22%3E%0A%0ASheets(%22Sheet2%22).Activate%0A%3CCODE%20for%3D%22%22%20hiding%3D%22%22%20rows%3D%22%22%3E%0A%0ASheets(%22Sheet3%22).Activate%0A%3CCODE%20for%3D%22%22%20hiding%3D%22%22%20rows%3D%22%22%3E%3C%2FCODE%3E%3C%2FCODE%3E%3C%2FCODE%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1518385%22%20slang%3D%22en-US%22%3ERe%3A%20VBAs%20in%20excel%20for%20beginners!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1518385%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3Blooks%20like%20its%20working%20thank%20you%20very%20much%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi,

I have a basic checklist with drop down lists of yes, no or n/a. For certain question if you select no you can skip down to a lower section and miss out some questions but to make the form more user friendly I'd like to hid the rows that aren't required. I have manage to do this for the first question however how do I add multiple commands for further questions? Here's what I have got for the first question:

 

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E5") = "No" Then
Rows("6:45").EntireRow.Hidden = True
Else
Rows("6:45").EntireRow.Hidden = False
End If
End Sub

 

I copied this command from a tutorial and changed the values but don't fully understand how the function works!

 

Many thanks

10 Replies
Highlighted

@North_Yorks 

Just repeat the code from If to End if , though with a different cell to check and different rows to hide or unhide.

Highlighted

@Riny_van_Eekelen 

Hi, thanks I've added them all but the first rule is not working it only hides 3 rows to the next rule when it should hide all questions to line 45 - all other rules are working correctly.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E5") = "No" Then
Rows("6:45").EntireRow.Hidden = True
Else
Rows("6:45").EntireRow.Hidden = False
End If
If Range("E7") = "No" Then
Rows("8:18").EntireRow.Hidden = True
Else
Rows("8:18").EntireRow.Hidden = False
End If
If Range("E20") = "No" Then
Rows("21:24").EntireRow.Hidden = True
Else
Rows("21:24").EntireRow.Hidden = False
End If
If Range("E26") = "No" Then
Rows("27:36").EntireRow.Hidden = True
Else
Rows("27:36").EntireRow.Hidden = False
End If
If Range("E38") = "No" Then
Rows("39:45").EntireRow.Hidden = True
Else
Rows("39:45").EntireRow.Hidden = False
End If
End Sub

Highlighted

@North_Yorks Insert "Exit Sub" before the first "Else". Then it works. When E5 = No, you want to hide all. No need to check any further. Without the exit code, the macro check the next condition. It is not No, thus it unhides the rows that were hidden in the first step and so on.

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("E5") = "No" Then
Rows("6:45").EntireRow.Hidden = True
Exit Sub
Else
Rows("6:45").EntireRow.Hidden = False
End If

If Range("E7") = "No" Then
Rows("8:18").EntireRow.Hidden = True
Else
Rows("8:18").EntireRow.Hidden = False
End If

If Range("E20") = "No" Then
Rows("21:24").EntireRow.Hidden = True
Else
Rows("21:24").EntireRow.Hidden = False
End If

If Range("E26") = "No" Then
Rows("27:36").EntireRow.Hidden = True
Else
Rows("27:36").EntireRow.Hidden = False
End If

If Range("E38") = "No" Then
Rows("39:45").EntireRow.Hidden = True
Else
Rows("39:45").EntireRow.Hidden = False
End If

End Sub

 

Highlighted

@Riny_van_Eekelen  Thank you it now works perfectly!

Highlighted

@North_Yorks Great! Glad I could help solving your problem.

Highlighted

@Riny_van_Eekelen spreadsheet it still working perfectly but there is a 'nice-ity' we'd like if it is at all possible to do!

Is it possible to have it, so when you open the document all the questions are collapsed - as if you have selected no for each, but without having 'no' typed/selected in them? But still have the options to select no yes n/a in the drop down lists I already have?

As I said its not a necessity but a nice to have!

 

Many thanks in advance

Highlighted

@North_Yorks You could paste the following code into the code window for the "Thisworkbook" tab in the VB editor, similar to how you pasted the other code into the Sheet1 code window. See if you can get it to work in your real workbook. It worked on my end.

Private Sub Workbook_Open()

Rows("8:18").EntireRow.Hidden = True
Rows("21:24").EntireRow.Hidden = True
Rows("27:36").EntireRow.Hidden = True
Rows("39:45").EntireRow.Hidden = True

End Sub

 

Highlighted

@Riny_van_Eekelen Hi, this worked great for my first worksheet but I have 2 more and they have a different amount of questions so different amount of rows need to be collapsed. Would I just copy the said command but specify which worksheet and which lines? How would I specify which worksheet? 

Many thanks

Highlighted

@North_Yorks See attached file with my original code in it. Three sheets, all with the same set-up, just for testing purposes. I believe it works as you want it.

 

In the code for "Thisworkbook", add a line that activates each sheet before you specify which rows to hide in it upon opening the workbook, similar to this:

Sheets("Sheet1").Activate
<code for hiding rows>

Sheets("Sheet2").Activate
<code for hiding rows>

Sheets("Sheet3").Activate
<code for hiding rows>

 

Highlighted

@Riny_van_Eekelen looks like its working thank you very much