I'm looking for information on the use of the 'Begins With' autofilter in VBA, the helpfiles do not list anything, and Googling for information hasn't worked (but it did lead me here).
Exactly what information do you want. Begins with is fairly self explanatory.
If you have "aa", "ab", and "bb" in your column, begins with "a" will filter out the "bb", leaving "aa" and "ab" visible, etc.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
Bear with me, this could get long and complicated.....
I have two ODBC sheets in the workbook and I have created a 'lookup' from one to the other. By using one field in the first sheet, I assign the cell value to a parameter, I autofilter the second sheet using the pasrameter and copy the result into a third sheet where additional information is also used.
We have modified our systems to provide a shortened initial field, but this is taking time to work through the databases.
Eventually all the fields will be the shortened version but it is expected that this may take upto six months. If there wasn't this delay I could carry on using the existing VBA code, but the code only works on fields exactly matching the original one.
In the meantime I need to search the second sheet using the shortened field whilst the original length field still exists in some records.
If I do the filter manually I can use the 'Begins With' autofilter to find the information I require, but I can't see any way of doing this in VBA, if I create a macro to see the result, 'Begins With' gives a field like '12345*' and uses the * as a wild-card, but I can't use the parameter value with a *.
I may be barking up the wrong tree, but I would appreciate some assistance.
I'm not sure I really understand all of what you say, but why can't you use the asterisk?
When you say parameter, do you mean a VBA variable or something else? If a variable, you can use [blue]Criteria = "=" & YourVariable & "*"[/blue]. If something else, come back.
Enjoy,
Tony
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
I'm still learning VBA and I couldn't think of the right term which was 'variable', Tony's previous reply has now sorted my existing problem, but I don't understand how the code works.
This something is the criterion for the autofilter; you want to select all cells with a value beginning with, in this case, your variable, partlookup. In other words all cells where:
[tt] cellvalue=partlookup*[/tt].
When specified as a criterion, the cellvalue is implied and all that needs specifying is:
[tt] =partlookup*[/tt].
The comparison string is composed of two literals ("=" and "*") and a variable which needs to be substituted by VBA for the actual value before passing the complete string to Excel. To make sure VBA interprets it like this you concatenate (using &) the separate elements with the literals in quotes and the variable without:
[tt] "=" & partlookup & "*"[/tt].
So, the first equals sign is saying that Criteria1 is equal to something and the second one is part of the criteria, saying that the cell value must be equal to something, hence:
-------------------------------------------------------------------------------------------- We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.