Solved

How do I search column for text, and then execute something if it finds it #2

Posted on 2006-11-28
8
175 Views
Last Modified: 2010-04-30
I just asked this question at http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22074669.html     

This code is very foreign, and I can't figure out how to do an easier search (below).

I need to search column C for the # symbol. If it finds it, execute code A, if not, execute code B?
0
Comment
Question by:tiehaze
  • 5
  • 3
8 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 18028621
You could have just included this in the previous question.. but if you want to keep these as separate questions:
Do you need to exclude cells containing ## ? That is what made the code so bloated, I had to factor those out.  If you don't need to exclude ##, then just use:

 Dim FND As Range
 Set FND = Columns("C").Find("#", LookIn:=xlValues, LookAt:=xlPart)
 If Not FND Is Nothing Then
  Call code_A
 Else
  Call code_B
 End If

Note that if you do need to exclude the ## ones, just use the same code as before, but substitute the "@" in the Like lines to "[#]" (for those @ not already in brackets).  # without the brackets is a wildcard for the Like operator, meaning "any digit".  Enclosing the # in brackets forces it to be the # character. By this I mean use "*[!#][#][!#]*" with the like operator.

Matt
0
 

Author Comment

by:tiehaze
ID: 18028693
What if the # is not the only character in the cell, and it was for example "@, #" How would I do that
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18028806
I included "LookAt:=xlPart" into the .Find method, so that it looks for the # anywhere in the cell.  If you want it to look for # being the ONLY character in the cell, change that to    LookAt:=xlWhole
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:tiehaze
ID: 18029691
Do you know how I can search for **? When I try with control find, it says almost every cell has it when it doesn't.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18031099
Sorry about the delay, holiday gift-exchange party here at work today.

Sure, you'll need to search for ~*~*
The * symbol is a wildcard meaning "anything", so thats why almost every cell has it.  If you put the tilda (next to the 1 key) before it, like ~* it will do a literal search for the "*" symbol.  For two, use ~*~*

Matt
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18031113
The same would apply for the ? symbol, as that means "any one character".  To find that you'd look for ~?
0
 

Author Comment

by:tiehaze
ID: 18031132
thanks so much
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18031250
Anytime.. this stays unlocked for 7 days so feel free to ask any more like that if you want
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question