Clear Contents Macro

spyldbrat

Board Regular
Joined
May 5, 2002
Messages
211
Office Version
  1. 365
I am a VERY beginner on macro's and can read minimal coding of a macro.

I found a macro on the internet that is supposed to clear the contents of all rows that contain specific data in a specific column. Of course, I had to modify the coding to match what my data. My data starts on row 8. I want it look at column H and if the word "null" exists, I want it to erase all the data in that row (either clear contents or deleting rows - I am not particular on this one). When I run the macro, it erase all data, starting from row 8 even if "null" does not exist.

Sub Clear_Contents()
For i = 8 To 1500
If Range("h" & i) <> "null" Then
Range("A" & i & ":M" & i).ClearContents
End If
Next i
End Sub


Also, my spreadsheet has multiple tabs (taken from another macro: "NY Reg", "NY Lic & REg", """Skip"" in Ramco", "Annual", "90 Day", "Support", "NY Term", "PA Stmt #", _
"PA Print Card Corp", "PA Print Card State", "PA Emp Ver", "PA Child Abuse", "NJN", "NJS", "Shannon"

Would I be able to add to the top of the macro the following so it would run on each tab at all at once or would I have to list each tab individually in the macro:

Sheets(Array("NY Reg", "NY Lic & REg", """Skip"" in Ramco", "Annual", "90 Day", "Support", "NY Term", "PA Stmt #", _
"PA Print Card Corp", "PA Print Card State", "PA Emp Ver", "PA Child Abuse", "NJN", "NJS", "Shannon")).Select
Sheets("NY Reg").Activate
 
I'd suggest something like this:

Code:
Sub DelNullRows()
Dim sh As Variant

    For Each sh In Array("NY Reg", "NY Lic & REg", """Skip"" in Ramco", "Annual", "90 Day", "Support", "NY Term", "PA Stmt #", _
                         "PA Print Card Corp", "PA Print Card State", "PA Emp Ver", "PA Child Abuse", "NJN", "NJS", "Shannon")


        Sheets(sh).Columns("H:H").Replace What:="null", Replacement:="#N/A", LookAt:=xlWhole, MatchCase:=False
        Sheets(sh).Columns("H:H").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
    Next sh
    
End Sub
You don't want to select/activate the sheets if you don't have to.
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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