how to delete the adjacent cells of the selected cells?

youngbella

New Member
Joined
Sep 27, 2020
Messages
19
Office Version
  1. 2010
Platform
  1. Windows
Dear all expert,

I am doing some macro vba to select a cells that contains specific text in a table. and I want to delete the adjacent cells cotents of the selected cells. I am new to vba and need your assistance.
Thank you.

On table 1 ,i have few "DONE" text. and I want delete the cells content next to the "DONE" text cells.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Assuming that your "DONE" is in column A and you want to delete column B

VBA Code:
Sub DeleteDONE()

Dim findMe As Range

For Each findMe In Range("A:A")
    If findMe = "DONE" Then
    findMe.Offset(, 1).Clear
    End If
Next findMe

End Sub
 
Upvote 0
Here is another macro (no loops) that you can also consider...
VBA Code:
Sub ClearNextToDone()
  With Range("B1:B" & Cells(Rows.Count, "A").End(xlUp).Row)
    .Value = Evaluate("IF(" & .Offset(, -1).Address & "=""Done"","""",IF(" & .Address & "="""",""""," & .Address & "))")
  End With
End Sub
 
Upvote 0
hi mr rick rothstein,
could you please explain how the code works?
sorry.
 
Upvote 0
Here is another macro (no loops) that you can also consider...
VBA Code:
Sub ClearNextToDone()
  With Range("B1:B" & Cells(Rows.Count, "A").End(xlUp).Row)
    .Value = Evaluate("IF(" & .Offset(, -1).Address & "=""Done"","""",IF(" & .Address & "="""",""""," & .Address & "))")
  End With
End Sub
hi mr rick rothstein,
could you please explain how the code works?
sorry.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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