Hiding Rows

MissOctober

New Member
Joined
May 24, 2018
Messages
16
I have rows (18:42) which is 25 rows.

i want to use a commandbutton that use
a. two ranges:eek:ne will cover the rows starting at 18 to the last hidden row, the other will not be set
b. Use a For Each loop to go through each row in the first range using the second range as the “each” item (i.e. For Each Range2 In Range1)
c. If the row (Range2) being checked is hidden set it to shown and then exit the loop
d. If the row is already shown go to the next row (Next Range2)

so when you click the button it would show row 18 and when u click again it will show the next row while the other rows are hidden



so would my code be like

Option Explicit
Private Sub CommandButton1_Click()
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Rows("18:42").Select

If Rows("18:42").Hidden =TrueThen
Selection
.EntireRow.Hidden =False
Else
Selection
.EntireRow.Hidden =True
EndIf</code>End Sub

https://unsee.cc/c831aaa4/
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
Code:
   With Range("A17:A42").SpecialCells(xlVisible).Areas(1)
      .Offset(.Count).Resize(1).EntireRow.Hidden = False
   End With
 
Upvote 0
How about
Code:
   With Range("A17:A42").SpecialCells(xlVisible).Areas(1)
      .Offset(.Count).Resize(1).EntireRow.Hidden = False
   End With



even when i put the correct code in. it isn't working :(

this what i got:

Private Sub CommandButton1_Click()


With Range("19:42").SpecialCells(xlVisible).Areas(1)
.Offset(.Count).Resize(1).EntireRow.Hidden = False
End With


End Sub
 
Upvote 0
The code I supplied was the correct code, based on your op. ;)
If row 18 can be hidden then the code needs to include row 17 to prevent errors.
Did you try my code?
 
Upvote 0
The code I supplied was the correct code, based on your op. ;)
If row 18 can be hidden then the code needs to include row 17 to prevent errors.
Did you try my code?

this what i did. i had click on format to hide the selected rows from 19:42 and when i click on the button its doing what i wanted
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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