Solved

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

Posted on 2013-01-18
8
966 Views
Last Modified: 2013-01-19
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
Comment
Question by:Geekamo
  • 4
  • 4
8 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38795360
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
 
LVL 1

Author Comment

by:Geekamo
ID: 38795377
@ ssaqibh,

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

~ Geekamo
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38795431
Just follow these steps

- Right-click on the sheet tab name
- select view code
- paste the code
- close vba window
0
 
LVL 1

Author Comment

by:Geekamo
ID: 38797811
@ 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38797818
Can you upload your workbook?
0
 
LVL 1

Author Comment

by:Geekamo
ID: 38797824
@ 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
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 38797853
Try

If Range("N30") <> "" Then Range("N31").MergeArea.ClearContents
0
 
LVL 1

Author Closing Comment

by:Geekamo
ID: 38797862
Great! It works perfectly! Thank you!

~ Geekamo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now