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.
Por vilc
Posts
#35692
tenho uma tabela com vários nomes, e na célula B4 digito o nome do cliente e faz o filtro normalmente.
consegui atraves do codigo abaixo.
como faço que para quando não achar o cliente ele me dar a Mensagem de cliente não encontrado


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$B$4" Then
If Target.Value <> "" Then
ActiveSheet.Range("$B$7:$C$7").AutoFilter Field:=2, Criteria1:="=" & Target.Value & "*", _
Operator:=xlAnd


Else


ActiveSheet.Range("$B$7:$C$7").AutoFilter Field:=2


End If
End If
Application.EnableEvents = True


End Sub
Por osvaldomp
#35693
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address <> "$B$4" Then Exit Sub
  Me.AutoFilterMode = False
  If Target.Value = "" Then Exit Sub
  If Application.CountIf([C:C], Target.Value & "*") = 0 Then MsgBox "CLIENTE NÃO ENCONTRADO": Exit Sub
   Me.Range("$B$7:$C$7").AutoFilter Field:=2, Criteria1:="=" & Target.Value & "*", _
    Operator:=xlAnd
End Sub
dica - desnecessário e desaconselhável o uso de Application.EnableEvents = False/True neste código (somente para filtrar)
Por osvaldomp
#35696
vilc escreveu:... e se eu quisesse colocar esse código num botão como ficaria...
Um código colocado em um botão não vai funcionar (e ainda o tamanho do botão terá que ser grandão pra receber o código ... ) ;)
Mas ... se você quiser pode colocar o código abaixo em um botão, porém coloque-o também em um módulo comum (Módulo1, Módulo2, ...) e vincule-o a um botão (pode ser o mesmo botão grandão em que você quer colocar o código) ? :|
Código: Selecionar todos
Sub AplicaFiltro()
 ActiveSheet.AutoFilterMode = False
 If [B4] = "" Then Exit Sub
 If Application.CountIf([C:C], [B4] & "*") = 0 Then MsgBox "CLIENTE NÃO ENCONTRADO": [B4] = "": Exit Sub
  ActiveSheet.Range("$B$7:$C$7").AutoFilter Field:=2, Criteria1:="=" & [B4] & "*", _
   Operator:=xlAnd
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