Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help! Stop Users from corrupting Drop Down Box Macro

Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?

In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.

My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.

Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True

If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)

End If
exitHandler:
Application.EnableEvents = True
Exit Sub

errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Help! Stop Users from corrupting Drop Down Box Macro

You don't say what type of dropdown you use and you didn't
mention the xl version. If you had said xl2007, I would have
ignored your post and you would be one of the lucky ones this time. <g

Some ideas (some not that good)...
1. Use dropdowns (comboboxes) from the "Control Tool Box".
They have a "ComboBox_Change" event that is separate from the
Worksheet_Change event.
2. Place all of your linked cells in the same column and check that
the change occurs in that column. If not, exit code.
3. Use Data Validation lists in the appropriate cells -
no change event necessary.
4. Lock the cells, so the user can't change them.
In your code, unlock the cells, do things, lock the cells.
(the linked cells, must remain unlocked)
--
Jim Cone
Portland, Oregon USA



"Dana M"

wrote in message
Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.

My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.

Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help! Stop Users from corrupting Drop Down Box Macro

Thanks for you ideas - I'm going to try them. Sorry for not saying that I'm
using Excel 2003, and I'm using Data Validation Drop Downs - settings: Allow
List, Source = ExpType, (a range name on a wksheet named Codes), Warning
after invalid data is entered "Please enter Exp Type before entering data."

"Jim Cone" wrote:

You don't say what type of dropdown you use and you didn't
mention the xl version. If you had said xl2007, I would have
ignored your post and you would be one of the lucky ones this time. <g

Some ideas (some not that good)...
1. Use dropdowns (comboboxes) from the "Control Tool Box".
They have a "ComboBox_Change" event that is separate from the
Worksheet_Change event.
2. Place all of your linked cells in the same column and check that
the change occurs in that column. If not, exit code.
3. Use Data Validation lists in the appropriate cells -
no change event necessary.
4. Lock the cells, so the user can't change them.
In your code, unlock the cells, do things, lock the cells.
(the linked cells, must remain unlocked)
--
Jim Cone
Portland, Oregon USA



"Dana M"

wrote in message
Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.

My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.

Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Help! Stop Users from corrupting Drop Down Box Macro

Jim, since I haven't done Combo Boxes before and since I've already got the
current drop downs on several pages in the worksheets and since users like
the way it works (as long as they click select) I thought I'd try your fix
#4, but I can't get it to work. Here's how I added my "unprotect" and "
protect" code to the original Worksheet Code. Note: I put ** in front of the
new code below - of course, there are no asteriks in the actual worksheet
code.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 3 Then
**ActiveSheet.Unprotect "mypassword"
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True

If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 4 Then
**ActiveSheet.Unprotect "mypassword"
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)

End If
exitHandler:
Application.EnableEvents = True
Exit Sub

errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
**ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True, Password:="mypassword"
End Sub


"Jim Cone" wrote:

You don't say what type of dropdown you use and you didn't
mention the xl version. If you had said xl2007, I would have
ignored your post and you would be one of the lucky ones this time. <g

Some ideas (some not that good)...
1. Use dropdowns (comboboxes) from the "Control Tool Box".
They have a "ComboBox_Change" event that is separate from the
Worksheet_Change event.
2. Place all of your linked cells in the same column and check that
the change occurs in that column. If not, exit code.
3. Use Data Validation lists in the appropriate cells -
no change event necessary.
4. Lock the cells, so the user can't change them.
In your code, unlock the cells, do things, lock the cells.
(the linked cells, must remain unlocked)
--
Jim Cone
Portland, Oregon USA



"Dana M"

wrote in message
Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.

My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.

Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Help! Stop Users from corrupting Drop Down Box Macro

Protecting validated entries is a recurring subject in the newsgroup
and there is no perfect answer.
See if the following gets you closer...
'--
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vReturn As Variant
If Target.Cells.Count 1 Then
GoTo exitHandler
ElseIf Target.Value = "" Then
GoTo exitHandler
ElseIf Target.Column = 3 Then
Application.EnableEvents = False
vReturn = Application.Match(Target.Value, _
Worksheets("Codes").Range("ExpType"), 0)
'Not in the list
If IsError(vReturn) Then
Application.Undo
MsgBox "Don't do that, use the dropdown. "
Else
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
ElseIf Target.Column = 4 Then
Application.EnableEvents = False
vReturn = Application.Match(Target.Value, _
Worksheets("Codes").Range("ExpOwner"), 0)
'Not in the list
If IsError(vReturn) Then
Application.Undo
MsgBox "Don't do that, use the dropdown. "
Else
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub
--
Jim Cone
Portland, Oregon USA




"Dana M"

wrote in message
Jim, since I haven't done Combo Boxes before and since I've already got the
current drop downs on several pages in the worksheets and since users like
the way it works (as long as they click select) I thought I'd try your fix
#4, but I can't get it to work. Here's how I added my "unprotect" and "
protect" code to the original Worksheet Code. Note: I put ** in front of the
new code below - of course, there are no asteriks in the actual worksheet
code.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 3 Then
**ActiveSheet.Unprotect "mypassword"
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True

If Target.Cells.Count 1 Then GoTo exitHandler

If Target.Column = 4 Then
**ActiveSheet.Unprotect "mypassword"
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)

End If
exitHandler:
Application.EnableEvents = True
Exit Sub

errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
**ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True, Password:="mypassword"
End Sub


"Jim Cone" wrote:

You don't say what type of dropdown you use and you didn't
mention the xl version. If you had said xl2007, I would have
ignored your post and you would be one of the lucky ones this time. <g

Some ideas (some not that good)...
1. Use dropdowns (comboboxes) from the "Control Tool Box".
They have a "ComboBox_Change" event that is separate from the
Worksheet_Change event.
2. Place all of your linked cells in the same column and check that
the change occurs in that column. If not, exit code.
3. Use Data Validation lists in the appropriate cells -
no change event necessary.
4. Lock the cells, so the user can't change them.
In your code, unlock the cells, do things, lock the cells.
(the linked cells, must remain unlocked)
--
Jim Cone
Portland, Oregon USA



"Dana M"

wrote in message
Note - current code is at the bottom of this question. I'm not sure, but
think this is called a worksheet event?
In columns C and D of several sheets in a template, I have drop down boxes
for selecting Type and Owner. If the user selects a Type Name, a Type
Abbreviation is returned (from a hidden "Code" sheet), ie; select Apple,
template shows AP, select Jack Web, template returns JW. The Type and Owner
drop downs are adjacent, in Columns C and D, but are not in every row
because of subtotals and blank rows.

My problem - users sometimes key in "AP" instead of selecting
"Apple", or copy/paste "AP" from another row. These actions are causing
errors.

Is there a way to either revise the following code so that copy/paste or
keying in an "AP" gives the same result
as selecting Apple from the Drop Down? Or alternately, not allow the user to
do anything but select - with a message if they attempt - that they need to
select from the drop down options? Here is my
current code - on right click of the worksheet tab/show code /
.........................
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 3 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("a1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpType"), 0), 0)
End If
Application.EnableEvents = True
If Target.Cells.Count 1 Then GoTo exitHandler
If Target.Column = 4 Then
If Target.Value = "" Then GoTo exitHandler
Application.EnableEvents = False
Target.Value = Worksheets("Codes").Range("d1") _
.Offset(Application.WorksheetFunction _
.Match(Target.Value, Worksheets("Codes").Range("ExpOwner"), 0), 0)
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
If Err.Number = 13 Or Err.Number = 1004 Then
GoTo exitHandler
Else
Resume Next
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel file opens Read-Only for different users...stop! Pradhan Excel Discussion (Misc queries) 1 November 3rd 08 06:12 PM
Stop users pasting data in cells trainerab Excel Discussion (Misc queries) 2 February 5th 08 05:37 PM
Formatting unlocked cells and stop users from pasting [email protected] Excel Programming 4 October 26th 07 01:55 PM
Stop users from inserting new lines and columns? KuroNeko Excel Programming 4 June 25th 07 04:44 PM
stop users from deleting rows wAyne Excel Discussion (Misc queries) 2 February 4th 06 05:57 PM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"