Solved

Maintain data integrity

Posted on 2011-03-01
13
228 Views
Last Modified: 2012-06-22
Experts,
In my spreadsheet, A12 is date entered, F12 is invoice date and G12 is invoice amount.
If either A12 or F12 are blank you cannot enter data in G12 - OK, that works.
However, the user can go back and delete the date in A12 or F12 or both afterwards. I would like to prevent that from happening such that if there is data in G12 you must have data in A12 and F12.
0
Comment
Question by:Frank Freese
  • 7
  • 6
13 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35011490
Would this solution work for you?

Id the data is deleted in A12 or F12 then G12 is cleared automatically?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35011512
Something like this?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A12")) Is Nothing Then _
    If Len(Trim(Range("A12").Value)) = 0 Then Range("G12").ClearContents

    If Not Intersect(Target, Range("F12")) Is Nothing Then _
    If Len(Trim(Range("F12").Value)) = 0 Then Range("G12").ClearContents
End Sub

Open in new window


Sid
0
 

Author Comment

by:Frank Freese
ID: 35011648
interesting idea - can I do this

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A12:A21")) Is Nothing Then _
    If Len(Trim(Range("A12:A21").Value)) = 0 Then Range("G12:G21").ClearContents

    If Not Intersect(Target, Range("F12:F21")) Is Nothing Then _
    If Len(Trim(Range("F12:F21").Value)) = 0 Then Range("G12:G21").ClearContents
End Sub
0
 

Author Comment

by:Frank Freese
ID: 35011714
tried that - it did not work.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35011716
Well not exactly.

You want to clear the entire range G12:G21 if say just F14 is empty? Maybe not.

Is this what you want?

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rng As Range, acell As Range
    Set Rng = Union(Range("A12:A21"), Range("F12:F21"))
    If Not Intersect(Target, Rng) Is Nothing Then
        For Each acell In Rng
            If acell.Value = 0 Then Range("G" & acell.Row).ClearContents
        Next
    End If
End Sub

Open in new window


Sid
0
 

Author Comment

by:Frank Freese
ID: 35011870
real close -
for example, the user can enter data in other cells such as A14:G14. When we clear data can we just go ahead and clear that range A14:G14, as example?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 35011967
You mean this?

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim Rng As Range, acell As Range
    Set Rng = Union(Range("A12:A21"), Range("F12:F21"))
    If Not Intersect(Target, Rng) Is Nothing Then
        For Each acell In Rng
            If acell.Value = 0 Then Range("A" & acell.Row & ":G" & acell.Row).ClearContents
        Next
    End If
    Application.EnableEvents = True
End Sub

Open in new window


Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35011974
But there is a hitch.

If the other cell is empty and you type anything in A12, it will still clear the row.

Sid
0
 

Author Comment

by:Frank Freese
ID: 35012418
woops - by clear the row - does that include formulars in H12...H14, which are protected
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35012424
No. Only cells from A to G

Sid
0
 

Author Comment

by:Frank Freese
ID: 35012443
perfect - thats what we wanted - can we try it?
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35012447
Sure :)

Sid
0
 

Author Closing Comment

by:Frank Freese
ID: 35037304
thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

747 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

14 Experts available now in Live!

Get 1:1 Help Now