I'm trying to clear the cell next to my dropdownlist. The goal is to clear the cell next to it when it changes. My code works well if the excel sheet is simple and not too much other data is on there. Now on the sheet I want to have it implemented it always gives me error VBA Runtime Error 1004 “Application-defined or Object-defined error”. How can I solve this? Another thing that makes it harder is that I have also other code in the Private Sub Worksheet_Change(ByVal Target As Range)
I think a solution could be to find a way to get it to work without using Target. Unfortunately I don't seem to find something that works without this.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True
If Target.Column = 2 And Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).ClearContents
End If
End Sub
Edit: part of the other code
With Sheet2
Select Case .Range("B2")
Case "C-shuttle 150 core"
.Range("F4:Q4").Locked = True
.Range("B2").Locked = False
Case "C-shuttle 250 core"
.Range("F4:I4").Locked = False
.Range("B2").Locked = False
.Range("J4:Q4").Locked = True
Case "C-shuttle 250 core with platfrom for DB or TD"
.Range("B4:Q4").Locked = False
.Range("B2").Locked = False
Case "C-shuttle 350 core"
.Range("B4:Q4").Locked = False
.Range("B2").Locked = False
End Select
End With
ExitHandler:
Sheet2.Protect Password:="Secret" ' ALWAYS PROTECT SHEET AT END ERROR OR NOT
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox Err.Number & " - " & Err.Description, vbCritical
Resume ExitHandler
Thanks a lot for your help!