Ah, found the problem. Column J is numeric, not text. Changing the "j="
line should do the trick.
j = WorksheetFunction.CountIf(ar.Offset(0, 8), "0") +
WorksheetFunction.CountIf(ar.Offset(0, 8), "<0")
If the numbers in column J are always positive then you can just use
j = WorksheetFunction.CountIf(ar.Offset(0, 8), "0")
Glad to help.
Mike
"leonidas" wrote:
Hi,
Thank crazybass2 for your help. There is only one last problem, and
that's why your code doesn't work. Column F is never really empty,
there is a formula in it and there is only an outcome when there is a
number in column J.
So I tried to change your code to the following code(change is bold):
Sub Hide_or_Unhide(rw As Long)
Dim rng As Range, i As Long, j As Long
Dim ar As Range
Set rng = Columns(2).SpecialCells(xlConstants, xlTextValues)
i = 0
j = 0
For Each ar In rng.Areas
i = i + 1
If i = rw Then
j = WorksheetFunction.CountIf(ar.Offset(0, *8*), "*")
If j 0 And ar.EntireRow.Hidden = False Then
Cells(ar.Row, "J").Select
Else
ar.EntireRow.Hidden = Not ar.EntireRow.Hidden
If ar.EntireRow.Hidden = True Then
Cells(ar.Row - 1, "J").Select
Else: Cells(ar.Row, "J").Select
End If
End If
Exit Sub
End If
Next
End Sub
But this doesn't work. When I put a number in column J the code still
hides the rows. Can you or someone else help me with this problem?
--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=551817