excel vba Question - if "text in cell list" and < than date today

awagnl

New Member
Joined
Mar 11, 2025
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,

im pretty new to excel vba and i couldnt find any code to make it work
to hide cells that are equal to "text in cell list" and < than date today

This is the current VBA Code: (Highlighted is the non working part)

---------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.Activate

If Not Application.Intersect(Range("B1"), Range(Target.Address)) Is Nothing Then


Select Case Target.Value

Case Is = "Dag Totaal": Rows("6:150").Rows.AutoFit

Case Is = "Week Totaal": Rows("6:150").RowHeight = 3

Case Is = "Dag Huidig" And "A"<Today : Rows("6:150").EntireRow.Hidden = True

Case Is = "": Rows("6:150").Rows.AutoFit

End Select

End If

End Sub

--------------------------------------------------------------------------------------------------------
 

Attachments

  • excel.jpg
    excel.jpg
    212.3 KB · Views: 2
Welcome to the Board!

I don't think you can add conditions to the "Case Is" lines - you can only check the value being returned from the "Select Case..." line.

You might be able to do something like this for that situation instead:
VBA Code:
Case Is = "Dag Huidig"
   If "A"< Today Then Rows("6:150").EntireRow.Hidden = True
except you would also need to define what "A" is. As you have it written, you are comparing the letter "A" to today's date.
If you are trying to look at the value in column A of the row that triggered the code to run, you could do this:
VBA Code:
Case Is = "Dag Huidig"
   If Cells(Target.Row, "A").Value < Today Then Rows("6:150").EntireRow.Hidden = True
 
Upvote 1
Solution

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