This problem has come back to haunt me again. I have posted this before (twice actually). One of the posts gave answer that didn't work with my code and It crashed violently. The other post gave me no answers but, I thought I had found a solution my self. I was wrong. These are the previous posts.
Users have found a way around the protections I "Thought" I put in. So I'm back to square one.
Here is the problem. The cells in column G are set to use combo boxes for their entries. When you select any cell in column G the combo box appears. After making a selection in the combo box the combo box goes away.
This is the combo box code.
To make the combo box go away you use the Tab key, Left/Right arrow keys, enter key, or left mouse click. Doing this will get the user to the next column either "H" or "I" (dependent on the selection in the combo box) Here is the code for the Key selections.
The codes for Tab, Enter, Left Arrow and Right arrow work great. It is left mouse click that will not work. You can select the combo box with the mouse, use the scroll bar with the mouse, and make a choice with the mouse. But after you have made the choice with the mouse, the cell in column H will not unlock or re-lock like it does with the other keys (Tab, Enter, R and L arrows). If it cannot be done with a mouse click, is there a way around it? Sorry to be long winded but I am trying to be thorough.
Thank you in advance,
Jim
Unlock a cell with a ComboBox entry
Hello all, I cannot figure out how to unlock a cell with a value from an activex combobox. The cells that link to the combobox are cells G6:G3000. The cells I need to unlock are in the next row H6:H3000. There was originally just a dropdown list in column G, but I updated to use a combobox as...
www.mrexcel.com
Keydown Keycode not working for mouse click
I thought I was getting better at this but again I am stumped. I had posted something nearly Identical to this recently. I didn't get a reply, I even thought I had found an answer. However, This is only partly true. Here is the link to my original post. Unlock a cell with a ComboBox entry...
www.mrexcel.com
Users have found a way around the protections I "Thought" I put in. So I'm back to square one.
Here is the problem. The cells in column G are set to use combo boxes for their entries. When you select any cell in column G the combo box appears. After making a selection in the combo box the combo box goes away.
This is the combo box code.
VBA Code:
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Dim nm As Name
Dim wsNm As Worksheet
Dim rng As Range
Set wsList = Sheets("List")
Set ws = ActiveSheet
On Error GoTo errHandler
If Target.Count > 1 Then GoTo exitHandler
Set cboTemp = ws.OLEObjects("MDList")
On Error Resume Next
If cboTemp.Visible = True Then
With cboTemp
.Top = 10
.Left = 10
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
End If
On Error GoTo errHandler
If Not Intersect(Target, Range("G10:G5000")) Is Nothing Then
If Target.Locked = True Then
GoTo exitHandler
Else
Application.EnableEvents = False
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 75
.Height = Target.Height + 13
.ListFillRange = str
If .ListFillRange <> str Then
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
Set wb = ActiveWorkbook
Set nm = wb.Names(str)
Set wsNm = wb.Worksheets _
(nm.RefersToRange.Parent.Name)
Set rng = wsNm.Range _
(nm.RefersToRange.Address)
.ListFillRange = "'" & wsNm.Name _
& "'!" & rng.Address
End If
.LinkedCell = Target.Address
If Target.Address <> "Not Listed" Then
Target.Offset(0, 1).ClearContents
End If
End With
cboTemp.Activate
End If
End If
exitHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
errHandler:
Resume exitHandler
End Sub
To make the combo box go away you use the Tab key, Left/Right arrow keys, enter key, or left mouse click. Doing this will get the user to the next column either "H" or "I" (dependent on the selection in the combo box) Here is the code for the Key selections.
VBA Code:
Private Sub MDList_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 9, 39, 13 'Tab, R-Arrow, Enter
If ActiveCell = "Not Listed" Then
ActiveCell.Offset(0, 1).Locked = False
ActiveCell.Offset(0, 1).Activate
Else
ActiveCell.Offset(0, 1).Locked = True
ActiveCell.Offset(0, 2).Activate
MDList.Visible = False
End If
End Select
Select Case KeyCode
Case 37 'L-Arrow
If ActiveCell = "Not Listed" Then
ActiveCell.Offset(0, 1).Locked = False
ActiveCell.Offset(0, -1).Activate
Else
ActiveCell.Offset(0, -1).Activate
ActiveCell.Offset(0, 2).Locked = True
MDList.Visible = False
End If
End Select
Select Case KeyCode
Case 1 'L-Mouse
If ActiveCell = "Not Listed" Then
ActiveCell.Offset(0, 1).Locked = False
ActiveCell.Offset(0, 1).Activate
Else
ActiveCell.Offset(0, 2).Activate
MDList.Visible = False
End If
End Select
End Sub
The codes for Tab, Enter, Left Arrow and Right arrow work great. It is left mouse click that will not work. You can select the combo box with the mouse, use the scroll bar with the mouse, and make a choice with the mouse. But after you have made the choice with the mouse, the cell in column H will not unlock or re-lock like it does with the other keys (Tab, Enter, R and L arrows). If it cannot be done with a mouse click, is there a way around it? Sorry to be long winded but I am trying to be thorough.
Thank you in advance,
Jim