VBA Hide rows if columns are "" and BLANK.

Lewzerrrr

Active Member
Joined
Jan 18, 2017
Messages
256
Hi,

I have an analysis sheet with lots of tables of data, each table differs in length based upon a cell reference but I have formulas dragged down to the max to compensate if the data exceeds the previous one e.g IF(B2="","",INDEX)

I need a code that will hide all rows where the values in column E = "" or BLANK but to keep a space inbetween each table.

I need it to unhide if the tables get larger etc.

I also need to keep static rows hidden with this VBA (R103, R190, R232).

See below for examples (first table is before hidden, second is after being hidden, third is when it the data changes, fourth is after third being hidden)

ABCDABCD
1Header1Header
2Data2Data
3Data3Data
4Data4Data
58
69Header
710Data
811Data
9Header15
10Data16Header
11Data17Data
1218Data
1319Data
1420Data
15
16Header
17Data
18Data
19Data
20Data

<colgroup><col width="56" span="11" style="width:42pt"> </colgroup><tbody>
</tbody>


ABCDABCD
1Header1Header
2Data2Data
3Data3Data
4Data4Data
5Data5Data
6Data6Data
7Data7Data
88
9Header9Header
10Data10Data
1115
1216Header
1317Data
14
15
16Header
17Data
18
19
20

<colgroup><col width="56" span="11" style="width:42pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
This might work - Add this to the sheet by right clicking and view code, Once the data in the sheet is changed it will check all the cells and hide them accordingly.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Rows.Hidden = False


LastRow = Cells(Rows.Count, "A").End(xlUp).Row


For i = 2 To LastRow


If Cells(i, 5).Value = "BLANK" Or Cells(i, 5).Value = "" Or IsEmpty(Cells(i, 5).Value) Then
    
    If Cells(i, 1) = "" And Cells(i - 1, 1) = "" Then
    
        Rows(i).Hidden = True


    End If


End If
Next i


Rows(103).Hidden = True
Rows(190).Hidden = True
Rows(232).Hidden = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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