unhide rows

pedroc74

New Member
Joined
Aug 23, 2011
Messages
12
Hello
I have a worksheet that only have 20 rows visible (a1 to A20) but I use 300 rows.
I need a macro that unhide row 21 if row 20 have data, 22 if 21 have data ... and stop only in row 300.
And I need that run every time I insert data

thank
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 300 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target.Value <> "" Then
    Target.Offset(1).EntireRow.Hidden = False
End If
End Sub
 
Upvote 0
Tanks .
It works almost perfect...you even understand my bad english :)
I need three more things.
When I insert data and press enter the active cell is the first unhide cell "300" . I need that select the above cell. ex. Insert data in cell 35, unhide 36 and select 36.
If I insert data in cell its ok, it works but some times I copy several cell form other sheet and i paste. When I do that VBA gives error.
The last thing is the printting. How can I select the printting area with hide rows? I only want print if cell have data.
 
Upvote 0
Pedro this code select the next cell as you want
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 300 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target.Value <> "" Then
    Target.Offset(1).EntireRow.Hidden = False
End If
Target.Offset(1).Select
End Sub

If I insert data in cell its ok, it works but some times I copy several cell form other sheet and i paste. When I do that VBA gives error.

i can do it by another code to unhide rows then hide unused

The last thing is the printting. How can I select the printting area with hide rows? I only want print if cell have data.
excel will just print unhide rows
 
Upvote 0
Thanks again.
My old sheet have 300 rows, 20 visible, 280 hidden and I could´t print only de visible rows so I already change all my sheet.
Now I have a sheet with only 20 rows with range A1:A20 to insert data, that gives me one printting page.
My idea is every time I have 20 ranges with data the macro automatically copy a row 10 rows above (hidden, with no data, only with my formulas. In between I have the colum results) and insert 20 new rows abobe de other rows.
I already found how to copy and insert rows.
1-My problem is run the macro automatically
2-Continued inserting 20 rows after I have a printting area filled knowing that every time I insert 20 rows the row to be copy is no longer de row 30 ( 10 above de first 20) and the row to copy the hidden row is no longer de row 21.
Can you help me ?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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