Not running code

MagicCarpet

New Member
Joined
Aug 1, 2024
Messages
3
Office Version
  1. 2010
Platform
  1. 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
 

Attachments

  • Screenshot (198).png
    Screenshot (198).png
    136.2 KB · Views: 17
  • Screenshot (199).png
    Screenshot (199).png
    141.3 KB · Views: 13

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top