ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I test for the first character (https://www.excelbanter.com/excel-programming/312073-how-do-i-test-first-character.html)

Kevlar

How do I test for the first character
 

I have a formula In cell A1 that has the value MP.
If the Value in cell A2 begins with the letter A I want a userform t
pop up. I've tried this and it does not work:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$2" Then
If Range("A1").Value = "MP" Then
If Left("A2", 1) = ("A*") Then
CheckTool.Show
End If
End If
End If
End Sub

Any ideas

--
Kevla
-----------------------------------------------------------------------
Kevlar's Profile: http://www.excelforum.com/member.php...nfo&userid=723
View this thread: http://www.excelforum.com/showthread.php?threadid=26522


Tom Ogilvy

How do I test for the first character
 

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$2" Then
If Range("A1").Value = "MP" Then
If Left("A2", 1) = "A" Then
CheckTool.Show
End If
End If
End If
End Sub

--
Regards,
Tom Ogilvy


"Kevlar" wrote in message
...

I have a formula In cell A1 that has the value MP.
If the Value in cell A2 begins with the letter A I want a userform to
pop up. I've tried this and it does not work:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$2" Then
If Range("A1").Value = "MP" Then
If Left("A2", 1) = ("A*") Then
CheckTool.Show
End If
End If
End If
End Sub

Any ideas?


--
Kevlar
------------------------------------------------------------------------
Kevlar's Profile:

http://www.excelforum.com/member.php...fo&userid=7231
View this thread: http://www.excelforum.com/showthread...hreadid=265222




kkknie[_187_]

How do I test for the first character
 

Get rid of the * after the A. You will only run the code when the firs
character in cell A2 is A* (which can never happen since that is tw
characters).



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26522


Steve Smallman

How do I test for the first character
 
change line 3 to read If LEFT(A2,1)="A" then....


"A2" is a string, not a cell reference, remove quotes
The value you are checking (the leftmost one character in cell A2) cannot
possibly equal the two character string "A*". Sorry, the pattern match
character doesn't work this way in Excel.

Steve
"Kevlar" wrote in message
...

I have a formula In cell A1 that has the value MP.
If the Value in cell A2 begins with the letter A I want a userform to
pop up. I've tried this and it does not work:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$A$2" Then
If Range("A1").Value = "MP" Then
If Left("A2", 1) = ("A*") Then
CheckTool.Show
End If
End If
End If
End Sub

Any ideas?


--
Kevlar
------------------------------------------------------------------------
Kevlar's Profile:
http://www.excelforum.com/member.php...fo&userid=7231
View this thread: http://www.excelforum.com/showthread...hreadid=265222





All times are GMT +1. The time now is 03:38 PM.

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