Filter numbers with textbox using 123132*
This was untested - Excel may want explicit conversion, so you may need
Criteria1:="=" & CLng(Criteria1) * 10, Operator:=xlAnd, _
Criteria2:="<" & (CLng(Criteria1) + 1) * 10
or use CDbl...
Bernie
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Marc,
Since they are numbers, you could use something like this if it is just
the last digit that is missing:
Criteria1:="=" & Criteria1 * 10, Operator:=xlAnd, _
Criteria2:="<" & (Criteria1 + 1) * 10
Or this, if you could have more than one digit missing
Criteria1:="=" & Criteria1 * 10^(CritLen - Len(Criteria1)),
Operator:=xlAnd, _
Criteria2:="<" & (Criteria1 + 1) * 10^(CritLen - Len(Criteria1))
HTH,
Bernie
MS Excel MVP
"Marc" wrote in message
oups.com...
On 31 Maj, 19:51, "Bernie Deitrick" <deitbe @ consumer dot org wrote:
Marc,
You need to get the syntax correct - the criteria string needs to be a
valid equality statement
Criteria1:=Criteria1 & "*", _
should be
Criteria1:= "=" & Criteria1 & "*", _
etc.
HTH,
Bernie
MS Excel MVP
"Marc" wrote in message
ups.com...
Hi,
I have a problem with my code. I have made a userform with a textbox
and am trying to filter a set of numbers in a column.
I can get it to work when I write the exact number in the textbox
which
is also in the list with numbers. But I want to use the "*" asterisk.
Lets say if 123123 is in list and the textbox-value is 1. Then the
number should not be filtered/hidden.
Private Sub TextBoxWorkCenter_Change()
Dim Criteria1 As Double 'Tried As
String
Criteria1 = Val(TextBoxWorkCenter.Value) 'Tried using: & "*"
and without Val()
Worksheets("test1").Range("B6:B1000").AutoFilter _
field:=1, _
Criteria1:=Criteria1 & "*", _
Operator:=xlOr, _
Criteria2:="Center*", _
VisibleDropDown:=False
End Sub
Hope that somebody can help me????
Cheers
Marc- Skjul tekst i anførselstegn -
- Vis tekst i anførselstegn -
Hi Bernie,
Thanks for the quick reply.
I have tried what you said but it does not help. It doesn't return any
numbers at all, not even the ones
that matches entirely. It hides all the rows except the ones
containing "center".
The numbers in the range are all formated as numbers. There are some
text cells too.
Can you or anybody else help me?
I have changed it to but it does not work:
Private Sub TextBoxWorkCenter_Change()
Dim Criteria1 As Double 'Tried As
String
Criteria1 = Val(TextBoxWorkCenter.Value) 'Tried using: & "*"
and without Val()
Worksheets("test1").Range("B6:B1000").AutoFilter _
field:=1, _
Criteria1:="=" &Criteria1 & "*", _
Operator:=xlOr, _
Criteria2:="Center*", _
VisibleDropDown:=False
End Sub
Best regards
Marc
|