Help Adjusting Macro

ExcelPadawan

New Member
Joined
Feb 25, 2015
Messages
13
Hi guys, I have a macro running on a worksheet I am building. Right now it is set to clear a range of drop down list cells in one column based on a selection changing in a single drop down cell for that same column.

In this case it means if cell C11 is changed in any way, C19-C20 will automatically go blank. I would like this same formula applied for each column, so if D11 is changed in any way, D19-D30 will go blank, and so on and so forth.

Below is my current code:

Private Sub Worksheet_Change(ByVal target As Range)
Application.ScreenUpdating = False
If Intersect(target, Range("C11")) Is Nothing Then Exit Sub
Range("C19:C30").ClearContents
End Sub

I've been playing with this code and can't figure out how to apply it so it functions in the same way but independently for each column, so changes in C will only affect column C, changes in D will only affect column D, etc.

Please help, and thank you!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
and so on and so forth.
The above statement is not a valid VBA parameter. When specifying parameters of operation, the specific limitations should be spelled out. It is assumed you want this event code to apply to any column with data where the cell in row 11 is changed.
Code:
Private Sub Worksheet_Change(ByVal target As Range)
    If Intersect(target, Rows(11)) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Application.ScreenUpdating = False
        With ActiveSheet
            Range(.Cells(19, target.Column), .Cells(30, target.Column)).ClearContents
        End With
    Application.ScreenUpdating = True
    Application.EnableEvents = True
 End Sub
 
Upvote 0
This worked thank you so much! I wish I were this proficient... I did some research online, but it's difficult to re-purpose example formulas when you are trying to do something very specific without background knowledge and it's not spelled out for you.

Please pardon my ignorance, but can you recommend any resources to expand my knowledge in building macros/VBA? An online course or a book that would resonate with a philistine such as myself?

Thank you for your insight; I truly appreciate your response. It works! Thank you again; I am thrilled!
 
Upvote 0
This worked thank you so much! I wish I were this proficient... I did some research online, but it's difficult to re-purpose example formulas when you are trying to do something very specific without background knowledge and it's not spelled out for you.

Please pardon my ignorance, but can you recommend any resources to expand my knowledge in building macros/VBA? An online course or a book that would resonate with a philistine such as myself?

Thank you for your insight; I truly appreciate your response. It works! Thank you again; I am thrilled!

You're welcome,
As hiker95 says, we have all been there and some of us, me included, haven't gone that much further along. But the elephant can be eaten one bite at a time.
Regards, JLG
 
Upvote 0
ExcelPadawan,

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0
So you guys helped me with the below formula to suit my purposes:


Private Sub Worksheet_Change(ByVal target As Range)
If Intersect(target, Rows(11)) Is Nothing Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
Range(.Cells(19, target.Column), .Cells(30, target.Column)).ClearContents
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


I was wondering if there was a way to program a command into this formula to undo changes to the cell by pressing ctrl+z. If not it's not a big deal but I was just curious if it's doable. Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,800
Members
449,337
Latest member
BBV123

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