Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default How can I use wildcards in IF statements and Macros

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default How can I use wildcards in IF statements and Macros

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.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How can I use wildcards in IF statements and Macros

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcards in If statements AJ[_4_] Excel Discussion (Misc queries) 4 July 28th 08 04:56 PM
Wildcards in RTD JKC Excel Discussion (Misc queries) 0 February 3rd 06 07:35 PM
Wildcards irresistible007 Excel Worksheet Functions 2 December 20th 05 10:12 AM
How do i start Macros using IF statements? xXx Katie xXx Excel Discussion (Misc queries) 2 August 22nd 05 03:13 PM
wildcards in vba shellshock Excel Discussion (Misc queries) 3 July 21st 05 07:37 PM


All times are GMT +1. The time now is 07:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"