Hide rows in a sheet according to selections on another sheet

caet_

New Member
Joined
Nov 22, 2020
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Hello!
First of all, wishes of a Happy New Year!

I am new to VBA and I'd like to ask for some help.

In sheet 1, there are several options that one can choose (A, B, C and D). More than option can be choosen.

After that, I would like that in sheet2, only the choices made in sheet1 appear in sheet 2.

For example, let's say I choose A and C on sheet 1. Rows 6 and 8 should be hidden and so on (the row 4 needs to be always visible).

Sheet 1:
question.xlsx
ABCDEF
1
2AAFALSE0
3BBFALSE0
4CCFALSE0
5DDFALSE0
6
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=+IF(D2=TRUE,1,0)


Sheet 2:

question.xlsx
ABCDEFG
1
2Product
3
4X (Common to all)
5A
6B
7C
8D
9
Sheet 2


Thank you a lot!

Th
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello!
First of all, wishes of a Happy New Year!

I am new to VBA and I'd like to ask for some help.

In sheet 1, there are several options that one can choose (A, B, C and D). More than option can be choosen.

After that, I would like that in sheet2, only the choices made in sheet1 appear in sheet 2.

For example, let's say I choose A and C on sheet 1. Rows 6 and 8 should be hidden and so on (the row 4 needs to be always visible).

Sheet 1:
question.xlsx
ABCDEF
1
2AAFALSE0
3BBFALSE0
4CCFALSE0
5DDFALSE0
6
Sheet1
Cell Formulas
RangeFormula
E2:E5E2=+IF(D2=TRUE,1,0)


Sheet 2:

question.xlsx
ABCDEFG
1
2Product
3
4X (Common to all)
5A
6B
7C
8D
9
Sheet 2


Thank you a lot!

Th
I have just realized that the checkboxes are not visible with the add-in. Therefore, I've taken a print screen:
 

Attachments

  • Capture.JPG
    Capture.JPG
    14 KB · Views: 8
Upvote 0
Are your checkboxes AxtiveX or Form Controls?
Also is the A, B etc next to the checkbox the actual caption, or just a value in the cell?
 
Upvote 0
Are your checkboxes AxtiveX or Form Controls?
Also is the A, B etc next to the checkbox the actual caption, or just a value in the cell?
Hello!
They are form controls. The A, B, etc are the actual captions
Thank you!
 
Upvote 0
Ok, how about
VBA Code:
Sub caet()
   With ActiveSheet.Shapes(Application.Caller)
      Sheets("sheet 2").Rows(.TopLeftCell.Row + 4).Hidden = .ControlFormat.Value <> 1
   End With
End Sub
and assign this to each checkbox
 
Upvote 0
Ok, how about
VBA Code:
Sub caet()
   With ActiveSheet.Shapes(Application.Caller)
      Sheets("sheet 2").Rows(.TopLeftCell.Row + 4).Hidden = .ControlFormat.Value <> 1
   End With
End Sub
and assign this to each checkbox
Thank you @Fluff, i had the idea that i had already questioned this, but I was not sure and couldn't find it.
When you say to assign it to each checkbox, do you mean to replace ".ControlFormat.Value" by "nameofthecheckbox.Value"?
And should I use this code in module or in the sheet?
Thank you a lot
 
Upvote 0
Hi to all.
I was trying something like this with event Worksheet_Activate instead of Worksheet_Change. Every time you move to sheet Part2 the marked boxes in Part1 will determine the hiding of the rows in Part2:
VBA Code:
Private Sub Worksheet_Activate()
    ActiveSheet.Unprotect Password:="123"
    Application.ScreenUpdating = False
    With Sheets("Part2")
        If Sheets("Part1").Range("D2") = True Then .Rows("5").EntireRow.Hidden = True
        If Sheets("Part1").Range("D3") = True Then .Rows("6").EntireRow.Hidden = True
        If Sheets("Part1").Range("D4") = True Then .Rows("7").EntireRow.Hidden = True
        If Sheets("Part1").Range("D5") = True Then .Rows("8").EntireRow.Hidden = True
    End With
    ActiveSheet.Protect Password:="123"
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi to all.
I was trying something like this with event Worksheet_Activate instead of Worksheet_Change. Every time you move to sheet Part2 the marked boxes in Part1 will determine the hiding of the rows in Part2:
VBA Code:
Private Sub Worksheet_Activate()
    ActiveSheet.Unprotect Password:="123"
    Application.ScreenUpdating = False
    With Sheets("Part2")
        If Sheets("Part1").Range("D2") = True Then .Rows("5").EntireRow.Hidden = True
        If Sheets("Part1").Range("D3") = True Then .Rows("6").EntireRow.Hidden = True
        If Sheets("Part1").Range("D4") = True Then .Rows("7").EntireRow.Hidden = True
        If Sheets("Part1").Range("D5") = True Then .Rows("8").EntireRow.Hidden = True
    End With
    ActiveSheet.Protect Password:="123"
    Application.ScreenUpdating = True
End Sub
Hello! Thank you!
I have tried, but it's not working properly :(
This is the attempt: questionA.xlsm
 
Upvote 0
Please explain, what does "not working properly" mean ?
As per my testing in your attached attempt you have 4 checked checkboxes so to me this means: non rows showing in Part2.
Manually unhide the rows in Part2, uncheck some checkboxes in Part1 and then go back to Part2. Isn't this what you are asking for ?
 
Upvote 0

Forum statistics

Threads
1,215,407
Messages
6,124,723
Members
449,184
Latest member
COrmerod

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