Hiding and unhiding Rows where the value > 0, < 1

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,973
Office Version
  1. 2019
Platform
  1. Windows
I am trying to get the following code to hide rows in Excel where the value in column C is greater than zero, but less than 1. The code " If c.Value <1 Then Rows(c.Row).Hidden = True" does not work

See Sample worksheet below. I need to hide the rows where the values are below 1 for eg 0.36


Nissan UNITS SOLD 1 TON/NAV 14 29.59%
Nissan UNITS RET STRADA 9 19.29%
Nissan UNITS SOLD 1400 LDV 9 18.73%
Nissan UNITS RT PUNTO/PANDA 4 8.61%
Nissan U/S FIAT PAL/PUNTO 4 8.24%
Nissan UNIT SLD PATROL/PATH 3 6.18%
Nissan UNIT SLD TERR/XTRAIL 2 3.75%
Nissan U/SLD NISS MICRA 1 2.06%
Nissan UNITS SOLD ALM/TIIDA 1 2.06%
Nissan UNITS SLD NIS CSTAR 0.36 0.75%
Nissan RET UNITS SOLD STILO 0.09 0.19%


Private Sub Worksheet_Activate()
Dim rng As Range, c As Range
Set rng = Columns(3).SpecialCells(xlCellTypeFormulas, 1)
Application.ScreenUpdating = False
For Each c In rng
    If c.Value <1 Then
        Rows(c.Row).Hidden = True
    Else
        Rows(c.Row).Hidden = False
    End If
Next c
Application.ScreenUpdating = True
End Sub


Your assistwance will be most appreciated

Howard
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Risk

Board Regular
Joined
Jul 27, 2006
Messages
71
This is what I use for the selected value to hide rows if equal to zero

Code:
 Sub HideZeroRows()
    Application.ScreenUpdating = False 'turn off screen updating

    Selection.EntireRow.Hidden = False
    Set wrkRange = Selection
    For Each rw In wrkRange.Rows
       If Application.Sum(rw) = 0
 Then
            rw.EntireRow.Hidden = True
        End If
    Next
    Application.ScreenUpdating = True 'refresh the screen

End Sub

You can change it to If Application.Sum(rw) < 1
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,973
Office Version
  1. 2019
Platform
  1. Windows
Hi OnlyaDrafter

Thanks for your help

Regards

Howard
 

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
Hi

Replace

Code:
If c.Value <1 Then

with

Code:
If c.Value > 0 And c.Value < 1 Then

HTH
 

Forum statistics

Threads
1,136,925
Messages
5,678,602
Members
419,774
Latest member
MooseWinooski

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
Top