Clearing cells based on a variable

PDaria

New Member
Joined
Nov 3, 2015
Messages
26
Hello,

How would I be able to clear the contents of adjacent cells based on the value in another? For instance if VDS column value is bigger than zero like 2, then cells B1 and B2 shall be cleared from their existing content that is currently "Good". If value is 4, then 1st 4 cells shall be cleared.

A B C D E F G H
Lane 1
Lane 2Lane 3Lane 4Lane 5Lane 6Lane 7
VDS
Good
GoodGood
Good
Good
2

<colgroup><col style="width:48pt" width="64" span="2"> <col style="width:48pt" width="64" span="3"> <col style="width:48pt" width="64" span="3"> </colgroup><tbody>
</tbody>
Card OffCard OffCard OffCard OffGood
Good
4

<colgroup><col width="64" span="2"><col width="64" span="3"><col width="64" span="3"></colgroup><tbody>
</tbody>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Perhaps..

Code:
Sub ClearValues()
    Dim Cel As Range
    For Each Cel In Range("H2", Range("H" & Rows.Count).End(xlUp))
        If Cel > 0 Then Range("A" & Cel.Row).Resize(, Cel).ClearContents
    Next Cel
End Sub

assumes VDS is in column H
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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