Solved

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

Posted on 2006-11-28
8
173 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

864 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

20 Experts available now in Live!

Get 1:1 Help Now