Forum Discussion

Cami96's avatar
Cami96
Copper Contributor
Jan 17, 2020
Solved

Allow Macro to Run on Locked Sheet

Hey everyone!   I have a recorded macro to filter out all blank cells in my table. The macro looks like this:   Sub filter_blank() ' '  filter_blank Macro ' '  Keyboard Shortcut: Ctrl+j '  ...
  • ChrisMendoza's avatar
    Jan 17, 2020

    Cami96 -

     

    Did you try https://www.thespreadsheetguru.com/the-code-vault/insert-delete-table-rows-with-worksheet-protection? 

     

    What you accomplished with the Macro Recorder you can also create as:

     

    Option Explicit
    Dim tableToDeleteRows As ListObject
    
    Sub deleteEmptyTableRows()
    
        Set tableToDeleteRows = ThisWorkbook.Sheets("Sheet1").ListObjects("Table1")
        
        Dim i As Long
        
        With tableToDeleteRows
            For i = .ListRows.Count To 1 Step -1
                If Trim(.ListRows(i).Range.Cells(1)) = vbNullString Then
                    .ListRows(i).Delete
                End If
            Next i
        End With
    
    End Sub

     

     

    It's a nice little procedure to get you into thinking programmatically.

Resources