September 1, 2021
Hi,
I am new to VBA and attempting to write some code that when run will hide all the rows that contain a date older than 2 weeks, but I keep running into an error in the highlighted row (see below) when testing the code that I'm not sure how to correct. Anyone know what I've done wrong?? There is also an attachment of the file for reference.
Sub Weeks2Hide()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Interface")
wsLR = ws.Cells(Rows.Count,1).End(x1Up).Row
For x = 4 To wsLR
'analyze date, see if it's 2 weeks or older
IF ws.Cells(x,7) <= Date - 14 Then
'hide
ws.Range("g" & x).EntireRows = True
End If
Next x
End Sub
Any help would be greatly appreciated! Thank you!
-Amanda
Trusted Members
December 20, 2019
wsLR = ws.Cells(Rows.Count,1).End(x1Up).Row
Firstly it looks like you have a 1 in the xlup part instead of an L
Secondly this is counting the rows in column 1 and you have nothing in column 1 so you need to change to 2
wsLR = ws.Cells(Rows.Count,2).End(xlUp).Row
Also
ws.Range("g" & x).EntireRows = True needs to be ws.Range("g" & x).EntireRow.Hidden = True
Answers Post
1 Guest(s)