Delete data from 2 columns if one column contains a word

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I need a macro that looks down column D and if a cell value is "Sold" deletes that cell and the one next to it (Column C)

thanks

Tony
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Option Explicit


Sub Tony()
Dim i As Long, lr As Long
lr = Range("D" & Rows.Count).End(xlUp).Row
For i = 1 To lr
If Range("D" & i) = "Sold" Then
Range("C" & i & ":D" & i).ClearContents
End If
Next i
End Sub
 
Upvote 0
Don't know how many rows you might have to cycle through like that but you could clear them all at once (assuming a heading row).
Code:
Sub Clear_Sold()
  Application.ScreenUpdating = False
  With Range("C1", Range("D" & Rows.Count).End(xlUp))
    .AutoFilter Field:=2, Criteria1:="Sold"
    If .SpecialCells(xlVisible).Cells.Count > 2 Then .Offset(1).Resize(.Rows.Count - 1).ClearContents
    .Parent.AutoFilterMode = False
  End With
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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