Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por gborniam
Posts
#29569
Boa tarde pessoal,

Quando eu preencho o valor da busca com um texto não exato a um valor da coluna (que está sendo utilizada como filtro) o programa funciona corretamente.

Imagem

Mas quando eu faço a busca por meio de um valor exato ocorre um problema:

Imagem

Eu não sei se tem algum problema com o operador Like, mas poderiam me ajudar? Estou anexando a pasta de trabalho para facilitar.

Ps: a procura ainda está case-sensitive.
Você não está autorizado a ver ou baixar esse anexo.
Avatar do usuário
Por alexandrevba
Avatar
#29579
Bom dia!!

Eu não tive o erro!
Procurei com o nome exato, parcial, incorreto, case-sensitive e não case-sensitive...

Att
Por gborniam
Posts
#29589
Que estranho, testei aqui de novo procurando pela matrícula e ocorreu o erro novamente. Pode tentar procurar pela matrícula 1 e depois pela matrícula 2 e me dizer se houve erro por favor?
Por gborniam
Posts
#29646
Resolvido!
When you develop custom functions, it’s important to understand a key distinction between functions that you call from other VBA procedures and functions that you use in worksheet formulas. Function procedures used in worksheet formulas must be passive. For example, code within a Function procedure cannot manipulate ranges or change things on the worksheet. An example can help make this clear.

You might be tempted to write a custom worksheet function that changes a cell’s formatting. For example, it could be useful to have a formula that uses a custom function to change the color of text in a cell based on the cell’s value. Try as you might, however, such a function is impossible to write. No matter what you do, the function won’t change the worksheet. Remember, a function simply returns a value. It cannot perform actions with objects.

That said, I should point out one notable exception. It is possible to change the text in a cell comment by using a custom VBA function.

Walkenbach, J. (2007). Microsoft Office Excel 2007 Power Programming with VBA. John Wiley & Sons, p 280.
Fonte: https://stackoverflow.com/questions/316 ... -add-fails
Portanto, ao invés de fill_filtered_table executar como uma função ela é executada como uma Sub e ListRows.Add agora tem argumentos diferentes.
Código: Selecionar todos
Public Sub fill_filtered_table(index As Integer, sought_value As String)
    Dim cell As Range, new_row As ListRow, clone As Range, cell_filtered As Range, i As Integer
    
    For Each cell In tabela_fonte.ListColumns(index).DataBodyRange
        If cell.Value Like "*" & sought_value & "*" Then
            Set clone = tabela_fonte.ListRows(cell.row - 1).Range
            ActiveWorkbook.Worksheets("Dados Filtrados").Select
            Set new_row = tabela_filtrada.ListRows.Add(Position:=1, AlwaysInsert:=False) '(AlwaysInsert:=True)
            
            'For i = 1 To tabela_filtrada.ListColumns.Count
                'new_row.Range.Cells(1, i).Value = clone(1, i).Value
            'Next i
            
            For Each cell_filtered In new_row.Range
                cell_filtered.Value = clone(1, cell_filtered.column)
            Next
        End If
    Next
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord