Solved

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

Posted on 2006-11-28
4
181 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 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

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

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 68
Automatic Email Reminder 4 77
Formula problem with Excel attachment 6 43
checkbox to hide entire section 10 63
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

730 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