Solved

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

Posted on 2006-11-28
8
174 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

809 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