Link to home
Start Free TrialLog in
Avatar of Jase Alexander
Jase AlexanderFlag 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
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
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 Like "*" & "x" & "*" Then
             If LCase(cell) = "x" Then
                 cell.EntireRow.Hidden = True
             End If
         Next cell
     End With
 End Su

Open in new window

regards
Avatar of Jase Alexander

ASKER

Hey RG

Thanks so much for your help

Just a quick question .... is there a way in which it can be modified to 'unhide' the rows if I re-click the button?

If not, no worries.

J
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks RG

Amazing solution as always - thank you so much for your help

J