PC Review


Reply
Thread Tools Rate Thread

How can I use wildcards in IF statements and Macros

 
 
AlanF
Guest
Posts: n/a
 
      22nd Nov 2009
I want to include in a Macro, something to take a particular action if the
active cell contains text beginning with X. I thought something based on an
IF statement, that included a wildcard, might work, e.g. IF(A1="X*,1,0). This
does not work though.
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      22nd Nov 2009
Sub JustDoIt()
Dim s As String
s = ActiveCell.Value
If Left(x, 1) = "X" Then
MsgBox "We should do something"
End If
End Sub

--
Gary''s Student - gsnu200909


"AlanF" wrote:

> I want to include in a Macro, something to take a particular action if the
> active cell contains text beginning with X. I thought something based on an
> IF statement, that included a wildcard, might work, e.g. IF(A1="X*,1,0). This
> does not work though.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Nov 2009
If you meant that you wanted to include this in a formula (not a macro), then:

=if(left(a1,1)="x",1,0)
or since you're returning 1 or 0:
=--(left(a1,1)="x")

Depending on what you're doing, you may have alternatives.

If I wanted to count the number of values in A1:A10 that started with an X, I
don't need to use an intermediate helper cell with a formula.

Instead, I could use:
=countif(a1:a10,"X*")
or just to show how to separate the characters:
=countif(a1:a10,"X" & "*")
or if you point to a different cell:
=countif(a1:a10,B1 & "*")

=sumif() can also use wild cards.

AlanF wrote:
>
> I want to include in a Macro, something to take a particular action if the
> active cell contains text beginning with X. I thought something based on an
> IF statement, that included a wildcard, might work, e.g. IF(A1="X*,1,0). This
> does not work though.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcards in If statements AJ Microsoft Excel Misc 4 28th Jul 2008 04:56 PM
Wildcards in IIF statements =?Utf-8?B?ZWxtbzI=?= Microsoft Access 3 17th Jan 2005 06:47 PM
Wildcards in IF statements Calvin Microsoft Excel New Users 1 8th Feb 2004 12:33 AM
Wildcards '*/' in Count IF Statements Fiona Microsoft Excel Misc 1 10th Dec 2003 07:44 AM
CASE statements using wildcards Tom Microsoft Access VBA Modules 1 16th Jul 2003 08:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:24 PM.