![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Posts: 9
|
Hi Here is my problem I have a spreadsheet that If cell "B" is set to the value of "IN" it will clear the rest of the cells in that row which is what I want it to do. I am trying to find someway of protecting against someone accidentally setting the value to IN. So I was wondering if there was a way to either have a pop up come up when you enter the value "IN" asking if you really wish to continue before it proceeds to clear the other cells or if there is a code I could use that if a user tried to enter a certain value in a cell it would require a password. Specificaly if the user enters the word "in" in cell "B" it will require a password
Here is the code that I am using to clear the other cells. any Ideas? Thanks! Private Sub Worksheet_Change(ByVal Target As Range) If UCase(Trim(Range("B" & Target.Row).Value)) = "IN" And Target.Column = 2 Then Range("$C$" & Target.Row & "1:$t$" & Target.Row) = "" End If End Sub |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,387
|
See if this is what you want. Right clickon your sheet tab, left click on View Code and paste this in.
Please note, this code takes the place of your existing code, and is only a suggestion. It worked fine when I tested it. I'd recommend you use this code first on a test file to see if I understood your question. Modify for password. ''''''''''''''''''''''''' Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column <> 2 Or Target.Cells.Count > 1 Then Exit Sub If Target.Value <> "IN" Then Exit Sub Target.Select Dim myPassword As String myPassword = InputBox("Please enter the password to proceed:", _ "Password is required to run this macro.") If myPassword <> "PASSWORD" Then MsgBox "Click OK to return to Report.", 16, _ "Cancelled -- correct password not entered." Target.Clear Else Target.EntireRow.Clear End If End Sub '''''''''''''''''''''' Any help? |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Posts: 9
|
Hey thanks that got me on the right path! I modified it to this and it works perfect! This way it doesnt clear any of the validations or conditional formatting for the cells
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column <> 2 Or Target.Cells.Count > 1 Then Exit Sub If Target.Value <> "IN" Then Exit Sub Target.Select Dim myPassword As String myPassword = InputBox("Please enter the password to proceed:", _ "Password is required to run this macro.") If myPassword <> "PASSWORD" Then MsgBox "Click OK to return to Report.", 16, _ "Cancelled -- correct password not entered." Target = " " Else Range("$C$" & Target.Row & "1:$t$" & Target.Row) = "" End If End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|