MagicCarpet
New Member
- Joined
- Aug 1, 2024
- Messages
- 3
- Office Version
- 2010
- Platform
- Windows
I have using below code to show a combobox named "tempcombo" linked with a cell which contain a validation list. After double clicking the cell the dropdown list of "tempcombo" get validation list of cell and after selecting and pressing Enter the selected item is shown in the cell. Normally I ran it in a unprotected sheet. As soon as I tried to protect the sheet the code doesn't run correctly. The dropdown list of dropbox "tempcombo" list does not appear. Is there anyone to help me.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, _
Cancel As Boolean)
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = Sheet1
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Cancel = True
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_____________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_LostFocus()
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
With Me.TempCombo
.Top = 5
.Left = 5
.Width = 0
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_______________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, _
Cancel As Boolean)
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = Sheet1
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Cancel = True
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_____________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_LostFocus()
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
With Me.TempCombo
.Top = 5
.Left = 5
.Width = 0
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_______________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub