View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Meg Partridge Meg Partridge is offline
external usenet poster
 
Posts: 10
Default Visual Basic Error Run Time Error, Type Mismatch

I tried this & now I get a different error ... Run-time error '1004',
Application-defined or object-defined error.

The reason I had to add that specific password protection is so columns will
be hidden based the choice in the drop down box.

The only thing that should be unprotected are specific columns depending on
a user's choice with a drop down box. There is a limited number of cells
that a user can input into.

"Rick Rothstein" wrote:

You missed the equal sign in your Target.Address test. Also, since only the
active sheet is being unprotected at the beginning of the routine, then I
would think that should be the only one being re-protected again inside this
routine. In addition to that, I noticed a mathematical relationship in the
Columns ranges versus the content of D3 that allows the entire Select Case
block to be replaced with a single line of code. Here is the routine after
the above are incorporated into it...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim wSheet As Worksheet
If Target.Cells.Count = 1 And Target.Address = "$D$3" Then
Me.Unprotect Password:="Secret"
Me.Columns("E:N").Hidden = False
Me.Columns(Chr(79 - Target.Value) & ":N").Hidden = True
Me.Protect Password:="Secret", UserInterFaceOnly:=True
End If
End Sub

This should do what the OP's original code was trying to do.

--
Rick (MVP - Excel)


"Jim Thomlinson" wrote in message
...
You have a couple of potential problems...
This line
If Target = Range("D3") Then
is the same as
If Target.Value = Range("D3").Value Then
You probably wanted
If Target.address "$D$3" Then

Your lastcase is the only one that does a protection and even though you
have userinterface set to true there will still be some things that macros
will not be able to do.

There is nothing in there that will necessarily generate a type
mismatch...
--
HTH...

Jim Thomlinson


"Meg Partridge" wrote:

Hello - I am receiving a Run-time error '13' Type mismatch for the code
that
I have. After reading the help section of microsoft, I am still lost!
The
code I am using is listed below. Any help would be greatly
appreciated!!!!
Thanks!

Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("D3") Then
Columns("E:N").Hidden = False
Select Case Target
Case Is = 1
Columns("N").Hidden = True
Case Is = 2
Columns("M:N").Hidden = True
Case Is = 3
Columns("L:N").Hidden = True
Case Is = 4
Columns("K:N").Hidden = True
Case Is = 5
Columns("J:N").Hidden = True
Case Is = 6
Columns("I:N").Hidden = True
Case Is = 7
Columns("H:N").Hidden = True
Case Is = 8
Columns("G:N").Hidden = True
Case Is = 9
Columns("F:N").Hidden = True
Case Is = 10
Columns("E:N").Hidden = True
For Each wSheet In Worksheets
wSheet.Protect Password:="Secret", _
UserInterFaceOnly:=True
Next wSheet
End Select
End If
End Sub