ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hiding rows where text not entered to right of colums A and B (https://www.excelbanter.com/excel-programming/437732-hiding-rows-where-text-not-entered-right-colums-b.html)

Aidan

Hiding rows where text not entered to right of colums A and B
 
I have a worksheet with narrative from A11:B60. Can someone provide me with a
macro that scans down rows 11 to 60 and if there is no content to the right
of columns A and B it hides these rows. i would still need to see the
headings for all the columns which stretch across to Column AD

Thanks in advance,


Aidan.

OssieMac

Hiding rows where text not entered to right of colums A and B
 
Hi Aidan,

Try the following. Note the comment and also that a space and underscore at
the end of a line is a line break in an otherwise single line of code.

I am a bit confused by "i would still need to see the headings for all the
columns which stretch across to Column AD". I should think the column
headers are in row 1 and will not be affected but if I have got it wrong then
please get back to me.

Sub HideBlankRows()
Dim rngToTest As Range
Dim cel As Range

'Edit "Sheet1" to your worksheet name
With Sheets("Sheet1")
Set rngToTest = Range(.Cells(11, "C"), _
.Cells(60, "C"))

For Each cel In rngToTest
If WorksheetFunction.CountA _
(Range(cel, .Cells(cel.Row, _
.Columns.Count))) = 0 Then

cel.EntireRow.Hidden = True

End If
Next cel

End With
End Sub

--
Regards,

OssieMac


"Aidan" wrote:

I have a worksheet with narrative from A11:B60. Can someone provide me with a
macro that scans down rows 11 to 60 and if there is no content to the right
of columns A and B it hides these rows. i would still need to see the
headings for all the columns which stretch across to Column AD

Thanks in advance,


Aidan.



All times are GMT +1. The time now is 10:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com