VBA clear contents of other adjacent columns

Dark0Prince

Active Member
Joined
Feb 17, 2016
Messages
433
Code:
Sub Button44_Click()
Dim rng As Range

Set rng = Range("B7:B50")
Set rngFound = rng.Find("ABQ")
If rngFound Is Nothing Then
    MsgBox "NOTHING TO CLEAR!!!"
Else:
Cells(rng.Row, 7).ClearContents
Cells(rng.Row, 8).ClearContents
End If

End Sub

Here's the code I'm starting with, and I'm not sure how I can use this to clear the 7th and 8th column if abq is found in the B range.

It's only clearing B7 for some reason.
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Sub Button44_Click()
Dim rng As Range

Set rng = Range("B7:B50")
Set rngFound = rng.Find("ABQ")
If rngFound Is Nothing Then
    MsgBox "NOTHING TO CLEAR!!!"
Else:
Cells(rng.Row, 7).ClearContents
Cells(rng.Row, 8).ClearContents
End If

End Sub

Here's the code I'm starting with, and I'm not sure how I can use this to clear the 7th and 8th column if abq is found in the B range.

It's only clearing B7 for some reason.
Here is an alternate macro that should do what you want...
Code:
Sub ClearIfABQ()
  [G7:H50] = [IF(B7:B50="ABQ","",IF(G7:H50="","",G7:H50))]
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,545
Messages
6,125,455
Members
449,228
Latest member
moaz_cma

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