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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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