VBA: Clear Contents of Cells after Cell Change

TheMAP

New Member
Joined
May 16, 2017
Messages
6
Hi everyone!

I know I am way overthinking this, but I can't figure out a more efficient string of code. I want to be able to clear the contents of a range of cells in the same row as a cell that changes. So I change cell B10 and it contents are cleared in cells C10:Q10. I want to be able to run this code as a button on a UserForm, so a Worksheet_Change sub won't work (in fact: this is all part of that kind of sub). My horribly inefficient code is below.

Any help is appreciated. Thanks!


Private Sub SubmitButton_Click()

Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 3).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 4).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 5).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 6).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 7).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 8).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 9).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 10).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 11).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 12).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 13).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 14).Address).Offset(-1, 0).ClearContents
Worksheets("Play-by-Play - Redux").Range(Cells(Selection.Row, 15).Address).Offset(-1, 0).ClearContents


End Sub

 

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.
Hi everyone!

I know I am way overthinking this, but I can't figure out a more efficient string of code. I want to be able to clear the contents of a range of cells in the same row as a cell that changes. So I change cell B10 and it contents are cleared in cells C10:Q10. I want to be able to run this code as a button on a UserForm, so a Worksheet_Change sub won't work (in fact: this is all part of that kind of sub). My horribly inefficient code is below.

Any help is appreciated. Thanks!


Private Sub SubmitButton_Click()


Worksheets("Play-by-Play - Redux").Cells(Selection.Row-1, 3).Resize(1,13).ClearContents


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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