- 19 Set 2018 às 22:51
#36916
Pessoal, boa noite. Sou novo aqui e talvez alguém possa me ajudar..
Encontrei na internet um código para que quando eu digite na combobox me apareça todos os nomes que comecem com as letras que digitei (código abaixo). Só que estou procurando uma maneira de que apareçam no dropdown todos os nomes que CONTENHAM as letras que digitei.
Ex: Digitei Am e ele me mostra Amanda, Amanhã, Amora, etc.. Queria que ao digitar Am aparecesse Camaro, Vamos, Fruta amora e por ai vai..
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
Muito obrigado
Encontrei na internet um código para que quando eu digite na combobox me apareça todos os nomes que comecem com as letras que digitei (código abaixo). Só que estou procurando uma maneira de que apareçam no dropdown todos os nomes que CONTENHAM as letras que digitei.
Ex: Digitei Am e ele me mostra Amanda, Amanhã, Amora, etc.. Queria que ao digitar Am aparecesse Camaro, Vamos, Fruta amora e por ai vai..
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
Muito obrigado