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
Solved

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

Posted on 2006-11-28
4
180 Views
Last Modified: 2010-04-30
I need to search column C for the @ symbol. If it finds it, execute code A, if not, execute code B. There might be a @@ symbol in this range. How do I search for only the one @ symbol?
0
Comment
Question by:tiehaze
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 18028310
tiehaze,

Based on your previous questions, I think you're running this from VBA and not a VB app.  If it is a vb app and you need help converting it, let me know:

Sub tiehaze()
 Dim FND As Range, FND1 As Range, FoundIt As Boolean
 Set FND = Columns("C").Find("@", LookIn:=xlValues, LookAt:=xlPart)
 If Not FND Is Nothing Then
  If FND.Value Like "*[!@]@[!@]*" Then
   FoundIt = True
  Else
   Set FND1 = FND
   Set FND = Columns("C").FindNext(FND)
   Do Until FND.Address = FND1.Address
    If FND.Value Like "*[!@]@[!@]*" Then
     FoundIt = True
     Exit Do
    End If
    Set FND = Columns("C").FindNext(FND)
   Loop
  End If
 End If
 If FoundIt Then
  Call code_A
 Else
  Call code_B
 End If
End Sub

I was guessing you were looking for an email address in there, so that the @ could not be the first or last character in the cell.  If you want it to check for the first or last as well (or only the @) then change the two lines that look like:
 If FND.Value Like "*[!@]@[!@]*" Then

To:
 If FND.Value Like "*[!@]@[!@]*" Or FND.Value Like "@[!@]*" Or _
  FND.Value Like "*[!@]@" Or FND.Value Like "@" Then

Matt
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18028337
One other minor addition.. the above will call code_A if a cell contains something like "a@b@@c" and you want that excluded (since it has @@ as well as just @), then simply use
 If Not FND.Value Like "*@@*" Then

Matt
0
 

Author Comment

by:tiehaze
ID: 18028455
Awesome... that worked perfect!
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18028495
Glad to help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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…

856 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