I'm still in the early learning stages of VBA. But, I have a column that has somewhat random text in it. I a trying to make it so that it clears the content from all cells that don’t contain a certain text string.
Ex: Clear every cell that doesn’t have the words “Company Code: “. So if B123 = "Company Code" it would NOT erase it, but if it says “Department” it will because it doesn’t contain that specified text string.
I am thinking that a simple “If, then” type function would work. If it contains the text string do nothing otherwise clear the content type of deal. I'm stuck though. Any suggestions? Here is what I got so far:
Sub Sample()
Dim ws As Worksheet
Dim aCell As Range
For Each aCell In Sheets("Data Dump").Range("F2:F1500")
Set aCell = Sheets("Data Dump").Columns("F").Find(What:="Company Code: ", LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If aCell Is Then Nothing
Else: aCell.ClearContents
End If
Next aCell
Application.ScreenUpdating = True
End Sub
Bookmarks