Redact Rows Based Upon Cell Contents

lneidorf

Board Regular
Joined
May 20, 2004
Messages
97
Office Version
  1. 365
Platform
  1. Windows
Hi there.

I've played around with this problem and had no success so far. A search of this forum yielded nothing.

I've got a some large spreadsheets with confidential information. I need to clear the contents and redact rows where cells contain specified text.

I'd like some VBA code that will do the following:
1. Look through the active area for specific text strings;
2. Where there's a match, clear the content of the entire row AND shade the row black (not then entire row, just the columns in use).

For example, my used range is A1:H200. Cells C15, D20, and F50 = "PHI".
As a result, I'd like to clear all contents of Rows 15, 20, and 50 AND shade with black fill A15:H15, A20:H20, & A50:H50.

Thanks!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Are you looking for something like this:

Code:
Sub ClearCon()


Dim rng As Range


Do
    Set rng = Range("A1:H200").Find(what:="PHI", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    If Not rng Is Nothing Then
        With Range(Cells(rng.Row, "A"), Cells(rng.Row, "H"))
            .ClearContents
            .Interior.Color = vbBlack
        End With
    End If
Loop Until rng Is Nothing


End Sub
 
Last edited:
Upvote 0
Another option
Code:
Sub lneidorf()
   With Range("A2:H200")
      .Replace "PHI", True, xlWhole, , False, , False, False
      Intersect(.SpecialCells(xlConstants, xlLogical).EntireRow, Range("A:H")).Interior.Color = vbBlack
      .SpecialCells(xlConstants, xlLogical).EntireRow.ClearContents
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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