Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-28
4
Medium Priority
?
194 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
[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
  • 3
4 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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

610 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