Solved

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

Posted on 2006-11-28
8
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

635 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