Hide rows if all cells return no values

kapi98

New Member
Joined
Jun 15, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi there,

Could you please advice how I could hide rows that don't return any value?
I've tried to adjust two different approaches but I guess they didn't work as there are still formulas in cells.

VBA Code:
Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For i = 1 To sheet.UsedRange.Rows.Count

    Set row = sheet.Rows(i)
    If WorksheetFunction.CountA(row) = 0 Then
        row.EntireRow.Hidden = True
    End If

Next i

VBA Code:
Dim neValues As Range, MyRange As Range

Set MyRange = Rows("2:40")

On Error Resume Next
Set neValues = Intersect(ActiveCell.EntireRow.SpecialCells(xlConstants), MyRange)
On Error GoTo 0

If neValues Is Nothing  Then
    row.EntireRow.Hidden = True
End If

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
What is in the row that doesn't return a value, numbers, text, formula...if formula what is it
 
Upvote 0
It's a formula that displays another sheet's values under certain conditions.
 
Last edited:
Upvote 0
Giving us the formula would have helped, but try
VBA Code:
Sub MM1()
Dim row As Range, r As Long, sh As Worksheet
Set sh = ActiveSheet
For r = 1 To sh.UsedRange.Rows.Count
    If Range("A" & r).Value = "" Then 'change the "" to 0 if thats what is returned
      Rows(r).Hidden = True
   End If
Next r
End Sub
 
Upvote 0
Excel Formula:
=IF(AND('SHEET1'!$M7<=A$2,'SHHET1'!$M7>44445,A$2<='SHEET1'!$Q7),'SHEET1'!$D7&" "&RIGHT('SHEET1'!$C7,3),"")

Thanks for your try. Unfortunately, it doesn't work well as the value is not always return in Column A.

1630974211736.png
 
Upvote 0
Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim lngMyRow As Long, lngLastRow As Long, lngLastCol As Long
    Dim strLastCol As String
    Dim ws As Worksheet

    Set ws = ThisWorkbook.ActiveSheet
    
    If WorksheetFunction.CountA(ws.Cells) > 0 Then
        Application.ScreenUpdating = False
        lngLastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        lngLastCol = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
        strLastCol = Split(ws.Cells(lngLastRow, lngLastCol).Address, "$")(1)
        For lngMyRow = lngLastRow To 1 Step -1
            If Evaluate("SUMPRODUCT(('" & ws.Name & "'!A" & lngMyRow & ":" & strLastCol & lngMyRow & "="""")*('" & ws.Name & "'!A" & lngMyRow & ":" & strLastCol & lngMyRow & "=""""))") = lngLastCol Then
                ws.Rows(lngMyRow).EntireRow.Hidden = True
            End If
        Next lngMyRow
        Application.ScreenUpdating = True
    End If

End Sub

Regards,

Robert
 
Upvote 0
Solution

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

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