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
[TABLE="width: 512"]
<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>[TR]
[TD="class: xl79, width: 64"]Lane 1
[/TD]
[TD="class: xl79, width: 64"]Lane 2[/TD]
[TD="class: xl79, width: 64"]Lane 3[/TD]
[TD="class: xl79, width: 64"]Lane 4[/TD]
[TD="class: xl79, width: 64"]Lane 5[/TD]
[TD="class: xl79, width: 64"]Lane 6[/TD]
[TD="class: xl79, width: 64"]Lane 7
[/TD]
[TD="class: xl79, width: 64"]VDS
[/TD]
[/TR]
[TR]
[TD]Good
[/TD]
[TD]Good[/TD]
[TD]Good
[/TD]
[TD]Good
[/TD]
[TD]Good
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]2
[/TD]
[/TR]
</tbody>[/TABLE]

<colgroup><col width="64" span="2"><col width="64" span="3"><col width="64" span="3"></colgroup><tbody>
[TD="width: 64"]Card Off[/TD]
[TD="width: 64"]Card Off[/TD]
[TD="width: 64"]Card Off[/TD]
[TD="width: 64"]Card Off[/TD]
[TD="width: 64"]Good
[/TD]
[TD="width: 64"]Good
[/TD]
[TD="width: 64"][/TD]
[TD="width: 64, align: right"]4
[/TD]

</tbody>
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,224,743
Messages
6,180,688
Members
452,994
Latest member
Janick

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