Hide Row Based on cell value which more than 45 days

JayHo

New Member
Joined
May 14, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I was creating an excel to monitoring the maintenance progress. i would like to hide the row which based on the cell value (date) more than 45days.

i have limited knowledge on VBA here is my core.
i set the date on colum S, and would like to hide the row base on the value on colum . can you point out the erron on my code below?

Sub Hidedatemorethan45days()
'
'
'
Dim cell As Range
For Each cell In Range("S6:S67")
If cell.Value < "45" Then
cell.EntireRow.Hidden = False
End If
If cell.Value > "45" Then
cell.EntireRow.Hidden = True
End If
Next cell
End Sub


thanks in advance
 

Attachments

  • Picture1.png
    Picture1.png
    97.8 KB · Views: 5
I think i find where the problem occur as the value included '' Shall be Inspected ASAP" in row S18, so the code would stop running at row 18 and occur the type mismatch. Can i add another condition for the code to run when encouter the '' Shall be Inspected ASAP" value?
 

Attachments

  • 1715844100206.png
    1715844100206.png
    118.8 KB · Views: 5
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I think i find where the problem occur as the value included '' Shall be Inspected ASAP" in row S18, so the code would stop running at row 18 and occur the type mismatch. Can i add another condition for the code to run when encouter the '' Shall be Inspected ASAP" value?

try:
VBA Code:
Sub Hidedatemorethan45days()
    Dim cell As Range
    For Each cell In Range("S6:S67")
        If IsDate(cell.Value) Or IsNumeric(cell.Value) Then
            If cell.Value - Date >= 45 Then
                cell.EntireRow.Hidden = True
            Else
                cell.EntireRow.Hidden = False
            End If
        End If
    Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,728
Messages
6,132,368
Members
449,720
Latest member
NJOO7

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