PDA

View Full Version : Hide/ unhide specific number of cells in a known range.



cyrilbrd
07-06-2015, 01:50 AM
Given in cells A19 to M39 a table with data
Headers are in Row 18
Rows 19 to 23 are visible
Rows 24 to 39 are hidden
I would like to set a VBA that would unhide 'x' number of rows or hide 'x' numbers of rows, maybe through a pop up window.
My intent is to be able to show either only one or more rows in the range 19:39
For instance one row would show only row19, 10 rows would shows range 19 to 29...
Looked into the following without much help so far:


.Rows.Hidden = False
.Rows("19" & ":39").Hidden = True

mperrah
07-06-2015, 07:58 AM
You could use something like this:

Sub Hide()
Dim r2 As Double
r2 = InputBox("Hide from 19 to what row?")
Rows("19:" & r2).EntireRow.Hidden = True
End Sub

Sub Show()
Dim r2 As Double
r2 = InputBox("Show from 19 to what row?")
Rows("19:" & r2).EntireRow.Hidden = False

End Sub

cyrilbrd
07-06-2015, 04:53 PM
Thanks, now wouldn't Dim as Long suffice here?

mperrah
07-07-2015, 10:36 AM
Thanks, now wouldn't Dim as Long suffice here?

Sure. You only have a limited number of rows in question,
Dim as Long covers ranges from -2,147,483,648 and 2,147,483,647
Dim as Integer is fine too (ranges from -32768 to 32767.
Dim as Byte would also work (less then 255).

cyrilbrd
07-07-2015, 05:37 PM
Noted. Thanks again for your feedback.