We help IT Professionals succeed at work.
Get Started

Excel 2007, Text Validation

642 Views
Last Modified: 2012-05-12
Thank you all for helping me!

Excel Workbook:
What I want is if a user selects  in ColC:

"N/A" Or  "FRD" Or "FOUO" Or "NATO-U" Or  "NATO-RD" Or "Ref"

Then ColD and ColE = N/A and the user can not change ColD or ColE

But If the user Deselects in ColC then ColD and ColE the user can change.

Here is my code, but when I try to use it goes into a loop and I have to use Task Manager to end it. It corrupts the Workbook and I have to get a backup copy to replace it even if I try and edit out the code it has already corrupted the workbook.

 
Dim cel As Range
    With Me
        If Not Intersect(.UsedRange, .Range("c2:c" & .Rows.Count)) Is Nothing Then
            Application.EnableEvents = False
           .Unprotect
            For Each cel In Intersect(.UsedRange, .Range("c2:c" & .Rows.Count)).Cells
            With cel.Offset(0, 1).Resize(1, 2)
                    If UCase(cel) = "N/A" Or UCase(cel) = "FRD" Or UCase(cel) = "FOUO" Or UCase(cel) = "NATO-U" Or UCase(cel) = "NATO-RD" Or UCase(cel) = "Ref" Then
                        .Locked = True
                        .value = "N/A"
                    Else
                        .Locked = False
                End If
                End With
            Next
            .Protect
            Application.EnableEvents = True
        End If
    End With

Open in new window


I also might get a Stack overflow error.

Please help me and thank you!
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 58 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE