ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do you say "begins with" (https://www.excelbanter.com/excel-programming/319409-how-do-you-say-begins.html)

[email protected]

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?


Frank Kabel

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?




Jake Marx[_3_]

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]


tjtjjtjt

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?



39N 95W

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-



tjtjjtjt

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?



Postman[_2_]

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



Postman[_2_]

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






All times are GMT +1. The time now is 07:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com