Reputation: 128
Trying to show just the subtotal rows (which are bolded) and hide everything else. Code crashes when it hits If c.Value.Font.Bold = False Then
.
Thanks
Sub HideEmptyRows() 'quote stack
Dim col As String
col = Range("c2").Value 'column to check
Dim sta As Integer
sta = Range("C3").Value 'start row
Dim fin As Integer
fin = Range("C4").Value 'finish row
Application.ScreenUpdating = True
Dim c As Range
For Each c In Range(col & sta & ":" & col & fin)
If c.Value.Font.Bold = False Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next c
End Sub
Upvotes: 1
Views: 187
Reputation: 54777
False,False,True
)).Option Explicit
Sub HideEmptyRows() 'quote stack
Dim ws As Worksheet: Set ws = ActiveSheet ' be more specific
Dim col As String: col = ws.Range("C2").Value 'column to check
Dim sta As Long: sta = ws.Range("C3").Value 'start row
Dim fin As Long: fin = ws.Range("C4").Value 'finish row
Dim rg As Range: Set rg = ws.Range(col & sta & ":" & col & fin)
Application.ScreenUpdating = False
' Hide the rows of the complete range.
rg.EntireRow.Hidden = True ' False
Dim c As Range
' Show bold rows only.
For Each c In rg.Cells
If c.Font.Bold = True Then ' False
c.EntireRow.Hidden = False ' True
End If
Next c
Application.ScreenUpdating = True
'MsgBox "Showing only subtotals.", vbInformation
End Sub
Upvotes: 0