PDA

View Full Version : Need help .Range.AutoFilter multiple field



Piergy
04-12-2017, 04:40 AM
Hi,
I should filter a database with the typed characters in the TextBox
I've found a tutorial on YouTube and I managed to add a TextBox and to give it a code.
I've written this code but it search the data only in field:=1
I would like to search the typed characters in all my columns but not satisfying all the columns at the same time.

That's my database:




Startup
Website
Email
Telefono
Description
Subsector
Technology/Skills
Mercato
Nazionalità


Domo Undici
//
info(at)equipment-undici(dot)it
//
Domo Undici trasforma qualsiasi impianto elettrico in un sistema intelligente e performante.
Energy Efficiency
Home Automation
B2C
Italia


1Con
//
hello(at)1control(dot)it
//
Un dispositivo universale che si chiama 1Con solo che copia e replica il tradizionale radiocomando
Equipment
Home Automation
B2C
Italia


Airg
//
info(at)airgloss(dot)com
//
Airg ha sviluppato due dispositivi a basso costo (presentati anche il mese scorso al CES di Las Vegas)
Health Safety
Home Automation
B2C
Italia



That's my code:
_
Private Sub TextBox1_Change ()

If Len(TextBox1.Value) = 0 Then Sheet.AutoFilterMode = False
Else
If Sheet1.AutoFilterMode = True Then
Sheet1.AutoFilterMode = False
End If
Sheet1.Range("A2:I" & Rows.Count).AutoFilter field:=1, Criteria1:="*" & TextBox1.Value & "*"

End If
End Sub
_

So if I type "equipment" I would like it to show me both Domo Undici and 1Con rows because in one of their columns there is the word "equipment" but not Airg cause in its row there isn't "equipment"

Sorry for my english
Thanks

mana
04-12-2017, 07:04 AM
Dim ws As Worksheet
Dim tbl As Range
Dim f As Range
Dim r As Range
Dim adr As String

Set ws = Sheets("Sheet1")
Set tbl = ws.Range("a3", ws.Range("I" & Rows.Count).End(xlUp))

tbl.EntireRow.Hidden = True
Set f = tbl.Find(What:=TextBox1.Value, LookAt:=xlPart)

If Not f Is Nothing Then
adr = f.Address
Do
If r Is Nothing Then
Set r = f
Else
Set r = Union(r, f)
End If
Set f = tbl.FindNext(f)
Loop Until f.Address = adr

r.EntireRow.Hidden = False

End If

mdmackillop
04-12-2017, 07:09 AM
You need to use Advanced Filter for this

Piergy
04-12-2017, 09:57 AM
Sorry, what should I put instead of "Range" when you say
Dim f As Range
Dim r As Range
Dim tbl As Range ?

Piergy
04-12-2017, 09:58 AM
Dim ws As Worksheet
Dim tbl As Range
Dim f As Range
Dim r As Range
Dim adr As String

Set ws = Sheets("Sheet1")
Set tbl = ws.Range("a3", ws.Range("I" & Rows.Count).End(xlUp))

tbl.EntireRow.Hidden = True
Set f = tbl.Find(What:=TextBox1.Value, LookAt:=xlPart)

If Not f Is Nothing Then
adr = f.Address
Do
If r Is Nothing Then
Set r = f
Else
Set r = Union(r, f)
End If
Set f = tbl.FindNext(f)
Loop Until f.Address = adr

r.EntireRow.Hidden = False

End If


Sorry, what should I put instead of "Range" when you say
Dim f As Range
Dim r As Range
Dim tbl As Range ?