code to make whole row unvisible

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
For range A9:A65500, if the formula results are zero, the corresponding whole row value will be unvisible.
I use Conditional Format---Fond---Color---White to make the whole row value unvisible. Here is combined results from Record Macro but it just did not work.
Any idea will be welcome.
Dennis

Code:
Sub Macro4()
Range("A9:A65500").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="0"
    Selection.EntireRow.FormatConditions(1).Font.ColorIndex = 2
End Sub
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

JC2710

Board Regular
Joined
Mar 10, 2008
Messages
164
Bit cumbersome but it works

Code:
Sub Macro1()
    
    Dim l As Long
    
    For l = 1 To 65500
        If Cells(l, 1) = 0 Then
            Rows(l).EntireRow.Font.ColorIndex = 2
        Else
            Rows(l).EntireRow.Font.ColorIndex = 0
        End If
    Next
End Sub
 
Last edited:

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,108
Office Version
  1. 365
Platform
  1. Windows
Right click the sheet's tab, View Code, and paste this.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim cell As Range
  If Not Intersect(Target, Range("A9:A6500")) Is Nothing Then
    For Each cell In Target
      If cell.Value = 0 Then
       cell.EntireRow.Font.ColorIndex = 2
        Else: cell.EntireRow.Font.ColorIndex = 0
      End If
    Next cell
  End If
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
If you want conditional formatting via code.
Code:
With Range("A9:A65500").EntireRow
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="=RC1=0"
    .FormatConditions(1).Font.ColorIndex = 2
End With
 

Watch MrExcel Video

Forum statistics

Threads
1,122,795
Messages
5,598,093
Members
414,212
Latest member
suxrule

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