Clear Contents in multiple cells based on certain criteria

alang84

New Member
Joined
Oct 21, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have data in cells T11:U19. I need to clear contents in the cells in U and adjacent cells in T if a zero is found in U. For example, if U15 contains a zero, I need to clear the contents in cells U15 and T15. I can't delete the cells because I have other data and I don't want the other data to shift. Any help is appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One option
VBA Code:
Sub Clear_Zeros()
    For Each c In ActiveSheet.Range("T11:T19")
        If c.Value = 0 Then c.Resize(, 2).ClearContents
    Next c
End Sub
 
Upvote 0
One option
VBA Code:
Sub Clear_Zeros()
    For Each c In ActiveSheet.Range("T11:T19")
        If c.Value = 0 Then c.Resize(, 2).ClearContents
    Next c
End Sub
Hi. The data is column T did not clear out.
 
Upvote 0
When I run the code, the sheet goes from this:
Book1
STUV
10
110data
120data
13not zerodata
14not zerodata
15not zerodata
160data
17not zerodata
180data
190data
20
Sheet1
Cell Formulas
RangeFormula
T12T12=1-1


to this:
Book1
STUV
10
11
12
13not zerodata
14not zerodata
15not zerodata
16
17not zerodata
18
19
20
Sheet1
 
Upvote 0
When I run the code, the sheet goes from this:
Book1
STUV
10
110data
120data
13not zerodata
14not zerodata
15not zerodata
160data
17not zerodata
180data
190data
20
Sheet1
Cell Formulas
RangeFormula
T12T12=1-1


to this:
Book1
STUV
10
11
12
13not zerodata
14not zerodata
15not zerodata
16
17not zerodata
18
19
20
Sheet1
Hi. The data will be in column t and the 0s will be in column u.
 
Upvote 0
Hi. The data will be in column t and the 0s will be in column u.
Doh! My sincere apologies - I must learn to read the question more carefully 😱

Try this instead...
VBA Code:
Sub Clear_Zeros()
    For Each c In ActiveSheet.Range("U11:U19")
        If c.Value = 0 Then c.Offset(, -1).Resize(, 2).ClearContents
    Next c
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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