Only show rows with empty cells inbetween

Baloubeer

New Member
Joined
Feb 7, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a list in excel with a fixed amount of rows (8 till about 1000) and each row has a variable amount of columns.
Within each row sometimes, the value is empty.
I need to write a VBA script to only show me the rows that contain cells with empty values between column C and the last column of each row with a value.
In below picture for example you can see these lines in red.
Line 3 has D3 empty
Line 6 has E6 empty
line 10 had G10 empty
line 13 has H13 empty
The green lines can be hided

I managed to find last row with values and I'm able to find last column in a row with a value but somehow I can't tie it together.

All help is appreciated.

Thanks in advance.
Wim

1647653146821.png
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This will check all rows between the first column in the used range and the last column in the row for empty cell(s), and hide the row if there are none.
VBA Code:
Sub Baloubeer()
Dim R As Range, FirstCol As Long, Rw As Range, Lcol As Long, HideRws As Range
Set R = ActiveSheet.UsedRange
For Each Rw In R.Rows
    Lcol = Rw.Find(what:="*", searchdirection:=xlPrevious).Column
    FirstCol = Rw.Cells(1, 1).Column
    If Application.CountA(Range(Cells(Rw.Row, FirstCol), Cells(Rw.Row, Lcol))) = Range(Cells(Rw.Row, FirstCol), Cells(Rw.Row, Lcol)).Count Then
        If HideRws Is Nothing Then
           Set HideRws = Rw.EntireRow
        Else
            Set HideRws = Union(HideRws, Rw.EntireRow)
        End If
    End If
Next Rw
If Not HideRws Is Nothing Then
    HideRws.EntireRow.Hidden = True
Else
    MsgBox "No rows without at least one empty cell found"
End If
End Sub
 
Upvote 0
I'm not sure if ..

  • You physically want to hide rows like @JoeMo's code does or simply highlight the relevant rows with colour, or
  • It is possible to have rows like 5 and/or 6 below

If just highlighting, could you consider Conditional Formatting instead of vba?

Baloubeer.xlsm
CDEFGHIJ
1datadatadata
2datadatadatadatadatadatadata
3datadatadatadatadatadatadatadata
4datadatadata
5
6datadatadatadata
7datadata
8datadatadatadatadata
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C1:J8Expression=XMATCH("?*",$C1:$J1,2,-1)-XMATCH("?*",$C1:$J1,2)+1<>COUNTIF($C1:$J1,"?*")textNO
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,356
Members
448,888
Latest member
Arle8907

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