Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2437
  • Last Modified:

Macro To Clear Contents of Cell IF Specific Cell Changes it's Value

Hello Experts,

I know how to copy and paste Macro code, but that's about it.  :) But I think this would be easy for someone to code.

If cell O16, changes it's value, then clear the contents of cell O17.

Thank you in advance for your help!

~ Geekamo
0
Geekamo
Asked:
Geekamo
  • 4
  • 4
1 Solution
 
Saqib Husain, SyedEngineerCommented:
Right-click on the sheet tab name and select view code and paste this code
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("o16")) Is Nothing Then
If Range("o16") <> "" Then Range("o17").ClearContents
End If
End Sub

Open in new window

This will not delete o17 if you delete o16. If you want to do that then delete the phrase

"If Range("o16") <> "" Then"
0
 
GeekamoAuthor Commented:
@ ssaqibh,

When I go into the coding area, what section do I paste your code into?

~ Geekamo
0
 
Saqib Husain, SyedEngineerCommented:
Just follow these steps

- Right-click on the sheet tab name
- select view code
- paste the code
- close vba window
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GeekamoAuthor Commented:
@ ssaqibh,

It's having a problem with the code...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("N30")) Is Nothing Then
If Range("N30") <> "" Then Range("N31").ClearContents
End If
End Sub

I am using merged cells.  Here's a screenshot.

Merged Cells
0
 
Saqib Husain, SyedEngineerCommented:
Can you upload your workbook?
0
 
GeekamoAuthor Commented:
@ ssaqibh,

Actually, I just emailed it to you - in relation to the other Q you're helping me on.  (Both questions are involving the same workbook)

~ Geekamo
0
 
Saqib Husain, SyedEngineerCommented:
Try

If Range("N30") <> "" Then Range("N31").MergeArea.ClearContents
0
 
GeekamoAuthor Commented:
Great! It works perfectly! Thank you!

~ Geekamo
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now