Avatar of Jase Alexander
Jase Alexander
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Deleting rows if cell contains text

HI Guys

Hope you can help

I have a simple to do list sheet detailing live and completed tasks. Each task has a progress bar on the right and in this, is a conditional format set so when the 'x' key is used, the cell turns green signifying progress.

Ive tried the below code so that if the button is pressed, it scans the sheet in column N and if it finds an 'x' in the cells in Column N, it will hide the row as the task is, in effect, complete.

The code ive assembled is as follows :-

Sub HideRows()
    Dim cell As Range
    Dim DataCount As Integer
    With Worksheets("ToDoList")
        DataCount = Range("A" & Rows.Count).End(xlUp).Row
        For Each cell In Range("N1:N" & DataCount)
            If cell.Contains("x")  Then
                Range(cell.Row).EntireRow.Hidden = True
            End If
        Next cell
    End With
End Sub

However, Im getting an error and not sure what I am doing wrong?

I have attached the sheet - any suggestions and help would be appreciated

J
ToDoList.xlsm
Microsoft OfficeMicrosoft ExcelVBA

Avatar of undefined
Last Comment
Jase Alexander

8/22/2022 - Mon