Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default How do you say "begins with"

Hi there,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default How do you say "begins with"

Hi
if left(activecell.value,1)="P" then
.....

--
Regards
Frank Kabel
Frankfurt, Germany
schrieb im Newsbeitrag
oups.com...
Hi there,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default How do you say "begins with"

Hi Michael,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?


Are you writing a VBA user-defined function (UDF), or are you looking for a
worksheet function solution?

If you want to use worksheet functions:

=IF(LEFT(A1,1)="p", "yes", "no")

If VBA:

If UCase$(Left$(ActiveCell.Value, 1)) = "P" Then
MsgBox "yes"
Else
MsgBox "no"
End If

The worksheet example isn't case sensitive. If you want only capital P's to
be matched, remove the UCase$() from the second example.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default How do you say "begins with"

Perhaps something like this?

Sub StartingwithP()
If Left(Selection.Value, 1) = "p" Then
MsgBox "woohoo"
End If
End Sub

tj

" wrote:

Hi there,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How do you say "begins with"


wrote in message
oups.com...
Hi there,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?


If Left(ActiveCell.Value,1) = "P" Then
Do Something
End If

-gk-




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default How do you say "begins with"

Mine should be ActiveCell.Value, like the other answers posted.

tj

"tjtjjtjt" wrote:

Perhaps something like this?

Sub StartingwithP()
If Left(Selection.Value, 1) = "p" Then
MsgBox "woohoo"
End If
End Sub

tj

" wrote:

Hi there,

I am writing a function that needs to have a statement in it that goes

If [data in ActiveCell] begins with "P"
then do something.

How do I do this?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How do you say "begins with"

Alternative, purely for the sake of diversity ...

If ActiveCell.Value Like "[Aa]*" Then
Do Something
End If

Oh, and I like the "Like" operator ;o)


| If Left(ActiveCell.Value,1) = "P" Then
| Do Something
| End If


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How do you say "begins with"

Alternative, purely for the sake of diversity ...

If ActiveCell.Value Like "[Aa]*" Then
Do Something
End If

Oh, and I like the "Like" operator ;o)


| If Left(ActiveCell.Value,1) = "P" Then
| Do Something
| End If




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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
How do I write "begins with"? Terri Excel Discussion (Misc queries) 1 February 22nd 07 01:48 PM
Sorting text that begins with "the" or "a" kcg727 Excel Discussion (Misc queries) 2 February 25th 06 10:44 PM
highest value in a Row, that begins with "21" or "28" Fritz Zwiefelhofer Excel Programming 1 February 8th 04 10:22 PM


All times are GMT +1. The time now is 08:10 PM.

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

About Us

"It's about Microsoft Excel"