Vba to hide rows based on a cell within another worksheet

Satheesh9012

New Member
Joined
Mar 19, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hi

I am trying to hide and unhide rows in a sheet(b) based on the values entered in sheet(a), the values range from 1 to 6, so if 1 is entered in sheet(a) sheet(b) should hide rows from 32:125, if 2 is entered rows 51 51:125 should be hidden, if no value then rows 32:125 should be hidden.

Please help
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "A1" Then
      With Sheets("B")
         .Rows("35:125").Hidden = False
         Select Case Target
            Case "", 1
               .Rows("35:125").Hidden = True
            Case 2
               .Rows("51:125").hidded = True
         End Select
      End With
   End If
End Sub
You need to put this in the code module for sheet a & it will hide the rows in sheet b when you manually change the value in A1 of sheet a
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "A1" Then
      With Sheets("B")
         .Rows("35:125").Hidden = False
         Select Case Target
            Case "", 1
               .Rows("35:125").Hidden = True
            Case 2
               .Rows("51:125").hidded = True
         End Select
      End With
   End If
End Sub
You need to put this in the code module for sheet a & it will hide the rows in sheet b when you manually change the value in A1 of sheet a
Thank you for this,

so i need to enter value(1,2,3,4,5,6), in the cell c13 in sheet(a) and rows should be hidden in sheet(b), so instead of a1 i can replace that with c13 right
 
Upvote 0
Oops I cant spell. change hidded to Hidden.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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