How do I test for the first character

  • Thread starter Thread starter Kevlar
  • Start date Start date
K

Kevlar

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
 
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
 
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).
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top