Worksheet 2: Search column X , if match, clear cell in column Y

albytross

New Member
Joined
Sep 22, 2021
Messages
24
Office Version
  1. 365
Hello!
I've got a simple problem and i've trawled MrExcel and a number of other sites for a solution without any luck. I've put together 20+ working macros into a workbook, but this is the one I'm stuck on..

Example functionality I'm looking for in a VBA script but can't get to work:
Search for "explicit_term" in Column G of Worksheet2

If "explicit_term" is found in Column G, then clear contents of cell in Column A & B - from the same row.

Thats all it is..
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
try this

VBA Code:
Sub ClearColumns()

Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long

Set ws = ThisWorkbook.Worksheets("Worksheet2")
lastRow = ws.Cells(ws.Rows.Count, "G").End(xlUp).Row

For i = 1 To lastRow
    If ws.Cells(i, "G").Value = "explicit_term" Then
        ws.Cells(i, "A").ClearContents
        ws.Cells(i, "B").ClearContents
    End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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