PDA

View Full Version : Automate Filter



marreco
03-07-2012, 02:14 PM
HI.

I have a code that works well.
What I want is to make it operate automatically.

I wish that every time it was entered data into a table in the worksheet named "Sales & Service", the code worked automatically for.

I'm trying to call this code
Private Sub Worksheet_Change(ByVal Target As Range)

Dim lrow As Long
lrow = Range("A" & Rows.Count).End(xlUp).Row
If Range("F" & lrow).Value <> "" Then
Call Filtrar
End If
End Sub


This code
Sub Filtrar()


Application.ScreenUpdating = False
If Worksheets("Resultado").Range("H2").Value <> "" Then

Worksheets("Resultado").Range("H2:H300").ClearContents

Sheets("Vendas & Servišos").Range("Nome_Misto").AdvancedFilter _
Action:=xlFilterCopy, _
Criteriarange:=Sheets("Vendas & Servišos").Range("X1"), _
Copytorange:=Sheets("Resultado").Range("H2"), _
Unique:=True
Range("H2:H594").Select
Sheets("Resultado").Range("$H$1:$H$399").RemoveDuplicates Columns:=1, Header:=xlYes
Range("H1").Select

End If
Application.ScreenUpdating = True
End Sub

see my attachment

Cross-Post
http://www.excelforum.com/excel-programming/818489-automate-filter.html

marreco
03-07-2012, 03:59 PM
Solved!! in http://www.thecodecage.com/forumz/pt...ic-filter.html


Private Sub Worksheet_Change(ByVal Target As Range)
Dim lrow As Long
lrow = Cells(Rows.Count, 1).End(xlUp).Row
If Range("F" & lrow).Value <> "" Then
Call Filtrar
End If
End Sub
Thank's :hi: