Macro to hide rows when certain cells are blank

Alberta Rose

New Member
Joined
Aug 29, 2014
Messages
1
Hello. We have updated our operating system and someone has made a timesheet form for ease of copy/paste into the system. The timesheet has 20 rows of various cost centres the person can charge to. Some weeks there will be no hours in these cells (M4 through Q25) and I need a macro to check the cells for a numeric value (hours), if none - then hide the row.

The spreadsheet columns that contain the hours per week (Monday to Sunday) are in columns M through Q. Cells A through L are populated with project information coding. So, if there are no hours charged to a specific job as per columns M - Q, then I want that row hidden.

Can anyone help me out with this please? Thanks
smile.gif
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Alberta,

Welcome to MrExcel.

you wrote "I need a macro to check the cells for a numeric value (hours)", does this mean there could be text in some of these cells?

FarmerScott
 
Upvote 0
Alberta,

try-

Code:
Sub Hide_Rows()
Dim ws As Worksheet
Dim x As Integer
Dim rng As Range

Set rng = Sheets("Sheet1").Range("M4:Q25")
    rng.EntireRow.Hidden = False
For x = 25 To 4 Step -1
    If Cells(x, 13).Value = "" And Cells(x, 14).Value = "" And Cells(x, 15).Value = "" And Cells(x, 16).Value = "" And Cells(x, 17).Value = "" Then
    Rows(x).EntireRow.Hidden = True
    End If
Next x
End Sub

Hope that helps?

FarmerScott
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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