Notifications
Clear all

Retorno de informação

3 Posts
2 Usuários
0 Reactions
1,174 Visualizações
(@robertonl)
Posts: 0
New Member
Topic starter
 

Boa noite.
Realizei uma adaptação em um código fonte, porém não estou conseguindo descobrir aonde encontra-se a informação na qual desejo mudar.
Quando digito o nome na textbox, desejo que ela procure a partir da linha dois, e também não apareça na listbox dados da ultima coluna (Email)

Sub FindAllMatches()
'Find all matches on activesheet
'Called by: TextBox_Find_KeyUp event

Dim SearchRange As Range
Dim FindWhat As Variant
Dim FoundCells As Range
Dim FoundCell As Range
Dim arrResults() As Variant
Dim lFound As Long
Dim lSearchCol As Long
Dim lLastRow As Long
   
    If Len(Cadastro_Fornecedor.Txt_Consulta.Value) > 1 Then 'Do search if text in find box is longer than 1 character.
        
        Set SearchRange = ActiveSheet.UsedRange.Cells
        
        FindWhat = Cadastro_Fornecedor.Txt_Consulta.Value
        'Calls the FindAll function
        Set FoundCells = FindAll(SearchRange:=SearchRange, _
                                FindWhat:=FindWhat, _
                                LookIn:=xlValues, _
                                LookAt:=xlPart, _
                                SearchOrder:=xlByColumns, _
                                MatchCase:=False, _
                                BeginsWith:=vbNullString, _
                                EndsWith:=vbNullString, _
                                BeginEndCompare:=vbTextCompare)
        If FoundCells Is Nothing Then
            ReDim arrResults(1 To 1, 2 To 2)
            arrResults(1, 1) = "No Results"
            arrResults(1, 2) = "No Results"
        Else
            'Add results of FindAll to an array
            ReDim arrResults(1 To FoundCells.Count, 1 To 2)
            lFound = 1
            For Each FoundCell In FoundCells
                arrResults(lFound, 1) = FoundCell.Value
                arrResults(lFound, 2) = FoundCell.Address
                lFound = lFound + 1
            Next FoundCell
        End If
        
        'Populate the listbox with the array
        Me.Lista_Fornecedor.List = arrResults
        
    Else
        Me.Lista_Fornecedor.Clear
    End If
        
       
End Sub

 
Postado : 02/09/2018 5:52 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Em sua rotina a pesquisa e feita na variável SearchRange (definida como range); e é utilizado o UsedRange (range utilizada) da planilha ativa, assim creio que inclusive a linha um e pesquisada
Os dados "achados" são armazenados inicialmente na variável arrResults; em duas colunas ++>valor localizado e seu endereço<++; e depois esses dados são "transferidos" para listbox.
Se deseja um retorno diferente, e dependendo do que deseja; talvez tenha que alterar inclusive a rotina de pesquisa, que creio seja uma UDF pois não conheço FindAll

 
Postado : 02/09/2018 7:42 pm
(@robertonl)
Posts: 0
New Member
Topic starter
 

Realizei mudança na estrutura do código, e funcionou perfeitamente

 
Postado : 07/09/2018 9:05 am