VBA-Excel. How can I handle hide/unhide rows based on Private Sub Worksheet_Change(ByVal Target As Range)?

Jmuniz_Vargas

New Member
Joined
May 21, 2013
Messages
6
Good morning to all,

I am a newbie in macros & VBA Excel. I wish to handle hide/unhide rows based on Private Sub Worksheet_Change(ByVal Target As Range). I have the following code event

Private Sub Worksheet_Change(ByVal Target As Range)​
ActiveSheet.Unprotect Password:="avalon"​
If Target.Column = 2 Then​
Application.EnableEvents = False​
Cells(Target.Row, 5).Value = Date + Time​
Application.EnableEvents = True​
End If​
ActiveSheet.Protect Password:="avalon"​
End Sub​

The idea is to aggregate this event (hide/unhide rows) when I entry data from 'B4'to 'B21' (Sometimes they will be filled totally and sometimes partially. It does not matter). Maybe, clicking in 'B21'or another event using double click in certain cell to activate unhide rows from 22 to 36 for follow up fill those rows. I hope to be clear, if not let me know to try to clarify my need to discover the proper code based on events.

Thanks in advance. I promise to learn quickly.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi,

are you saying that when you change the value in a cell in the range B4:B21, you would like to hide or unhide a row in the range 22:36?

To hide rows you can use:

Code:
Range("B22").rowheight = 0
'OR
Range("B22").entirerow.hidden = True

And to unnhide them:
Code:
Range("B22").rowheight = 15 ' This is the default height.  Adjust the number as required.
'OR
Range("B22").entirerow.hidden = False

Hope that get you on your way.

Cheers
JB
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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