In my last blog post, I demonstrated how to highlight only certain words within cells in MS Excel. In this blog post I will demonstrate how to delete contents of cells which cells have a specific background color.
In the data set above, I want to remove the content of cells which contain background color of red. Here is the macro code that will perform this task once run.
Sub Delete() Range ("A2:D12").Select For Each Cell In Selection If Cell.Interior.Color = Excel.XlRgbColor.rgbRed Then Cell.Clear End If Next End Sub
Now I will run the Macro.
Here is the outcome.
Note that the color could be changed to any given color by revising the fourth line of the code (i.e. …= Excel.XlRgbColor.rgbRed) based on the list provided in the reference list
Reference: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/xlrgbcolor-enumeration-excel
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
CategoriesArchives
June 2020
|