The VBA code below that goes into the worksheet, hides rows that contain 0 or "" blank. And unhides everything else. It works good. However...
--------------
FIRST OF ALL:
It only looks for NUMBERS not text. So, if a cell contains TEXT and not a number, then it is hidden too. But that's not good for me, because I need it to look for both numbers or text. If "" blank then hide, if there is text or numbers then unhide. Help me fix that please!
Option Explicit
Private Sub Worksheet_Activate()
Dim HiddenRow&, RowRange As Range, RowRangeValue&
'*****************************
'< Set the 1st & last rows to be hidden >
Const FirstRow As Long = 6
Const LastRow As Long = 200
'< Set the columns that may contain data >
Const FirstCol As String = "A"
Const LastCol As String = "B"
'*****************************
ActiveWindow.DisplayZeros = False
Application.ScreenUpdating = False
For HiddenRow = FirstRow To LastRow
'Range of columns
Set RowRange = Range(FirstCol & HiddenRow & _
":" & LastCol & HiddenRow)
'sums the entries in cells in the RowRange
RowRangeValue = Application.Sum(RowRange.Value)
If RowRangeValue <> 0 Then
'there's something in this row - don't hide
Rows(HiddenRow).EntireRow.Hidden = False
Else
'there's nothing in this row yet - hide it
Rows(HiddenRow).EntireRow.Hidden = True
End If
Next HiddenRow
Application.ScreenUpdating = True
End Sub
-----------------------
AND SECONDLY:
It will not allow me to just select Col "A"... I have to have a range like A:B... I managed a way around that, but if the code can be fixed that would be better. What I did is add a new column that is always blank, and hid it....
When I edit the code to:
'< Set the columns that may contain data >
Const FirstCol As String = "A"
Const LastCol As String = "A"
Then an error comes up saying:
"Run-time error '13':
Type mismatch"
I'm a layman to coding... So, can you please send me a new code that will work for me?\
Thank you!
Bookmarks