Solved

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

Posted on 2006-11-28
8
172 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now