I found some code to help with the text being too small to read in the drop down list. It is a double click to open a combo box. I have now created code to open a comments box when a certain condition is not reached. When I try to combine the two codes my comments box code doesn’t work.
How can I combine the two codes to make them both work and most importantly, why is breaking?
Below is the code combined.
Note*** if I do not activate the combo box the other code works and the comment box code works like it is supposed to.
Private Sub Worksheet_Change(ByVal Target As Range)
Static sName As String
Dim iLen As Long
Dim str As String
Set ws = ActiveSheet
If Len(sName) = 0 Then sName = Application.UserName & ":"
With Target(1)
If Intersect(.Cells, Range("U17:EZ74")) Is Nothing Then Exit Sub
If .HasFormula Then Exit Sub
If .Value = Cells(.Row, "B") Or .Value = Cells(.Row, "C").Value Then
If bHasComment(.Cells) Then .Comment.Delete
Else
.Select
If Not bHasComment(.Cells) Then
.AddComment
Else
iLen = Len(.Comment.Shape.TextFrame.Characters.Text)
End If
With .Comment.Shape.TextFrame
.AutoSize = True
.Characters(Start:=iLen + 1).Insert IIf(iLen, vbLf, "") & sName & vbLf
.Characters(Start:=iLen + 1, Length:=Len(sName)).Font.Bold = True
End With
With .Comment
.Visible = True
Application.SendKeys "+{F2}"
.Visible = False
End With
End If
End With
End Sub
Function bHasComment(cell As Range) As Boolean
On Error Resume Next
bHasComment = cell.Comment.Parent.Address = cell.Address
End Function
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.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
Application.EnableEvents = False
'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:
Application.EnableEvents = True
Exit Sub
End Sub
Thank you,
Ted
Bookmarks