Hello everyone, please see below the code i'm using to create combo box where there is a drop down list to increase it's size and it works perfectly.
now i;m trying to protect all the macros so I've added the following two lines to the start of the subs and the end of them.
when i try to do the same for the following code it keeps giving me errors for that edit is enabled because the sheet is protected.
if i don'd add any protection it unprotects the whole worksheet.
any ideas?
ThisWorkbook.Worksheets("Cell 1").Unprotect ("1234")
ThisWorkbook.Worksheets("Cell 1").Protect ("1234")
these are the lines to protect and unprotect that i'm using
Private Sub TempCombo_Change()
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xCombox As OLEObject
Dim xStr As String
Dim xWs As Worksheet
Dim xArr
Set xWs = Application.ActiveSheet
On Error Resume Next
Set xCombox = xWs.OLEObjects("TempCombo")
With xCombox
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
If Target.Validation.Type = 3 Then
Target.Validation.InCellDropdown = False
Cancel = True
xStr = Target.Validation.Formula1
xStr = Right(xStr, Len(xStr) - 1)
If xStr = "" Then Exit Sub
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
If .ListFillRange = "" Then
xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
End If
End Sub
now i;m trying to protect all the macros so I've added the following two lines to the start of the subs and the end of them.
when i try to do the same for the following code it keeps giving me errors for that edit is enabled because the sheet is protected.
if i don'd add any protection it unprotects the whole worksheet.
any ideas?
ThisWorkbook.Worksheets("Cell 1").Unprotect ("1234")
ThisWorkbook.Worksheets("Cell 1").Protect ("1234")
these are the lines to protect and unprotect that i'm using
Private Sub TempCombo_Change()
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xCombox As OLEObject
Dim xStr As String
Dim xWs As Worksheet
Dim xArr
Set xWs = Application.ActiveSheet
On Error Resume Next
Set xCombox = xWs.OLEObjects("TempCombo")
With xCombox
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
If Target.Validation.Type = 3 Then
Target.Validation.InCellDropdown = False
Cancel = True
xStr = Target.Validation.Formula1
xStr = Right(xStr, Len(xStr) - 1)
If xStr = "" Then Exit Sub
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
If .ListFillRange = "" Then
xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
End If
End Sub