Clear contents for cells with specific values

thechad

Board Regular
Joined
Apr 28, 2014
Messages
117
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi all...I have repurposed this for my needs and it works awesome. However, I am wondering how to clear contents for multiple values instead of just one? I have included my current code. As you can see I have "Black" that defines the rows that I would like cleared, but would like to include "Blue" & "Red" or others as I need them. They won't change very often so I would just change the VBA.

Thanks in advance!

VBA Code:
    Dim myLastRow As Long
    Dim i As Long
    
    Application.ScreenUpdating = False
    
'   Find last row
    myLastRow = Cells(Rows.Count, "K").End(xlUp).Row
    
'   Loop through range
    For i = 5 To myLastRow
        If Cells(i, "K").Value = "Black" Then Range(Cells(i, "A"), Cells(i, "W")).ClearContents
    Next i
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
One way.
VBA Code:
    '   Loop through range
    For i = 5 To myLastRow
        Select Case Cells(i, "K").Value
            Case "Black", "Red", "Blue"
                Range(Cells(i, "A"), Cells(i, "W")).ClearContents
        End Select
    Next i
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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