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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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
Back
Top