comparing text in if statement

  • Thread starter Thread starter Dolemite
  • Start date Start date
D

Dolemite

ok, I give up, I can't find my answer by searching...

I have a cell that contains a text string, depending on what letter
that string starts with, I need to use a particular formula. I am
trying to accomplish this in VB, but have had no luck getting my if
statement to work...

example


A B C
1 ip30 Formula 1 result i
2 np30 Formula 2 result
3 ip35 Formula 1 result

using the above sheet as reference, column A is the only column that I
will be entering data.....here is what I want my if/then statement to
look like

if(left(range(targetAddress),1) = c1 then
***use formula 1 ***
else
***use formula 2***
end if

keep in mind this is part of a sub that is executed anytime a value in
column A changes. So as soon as I enter my data in column A, the macro
runs and fills out the rest of my columns for me, but how it fills out
the other columns is dependant on the first character of the string
entered in column A.

I hope this makes sense. If not say so and will try and clarify.
Thanks in advance for any help.
 
Does this help?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row > 1 _
And Target.Value <> Empty Then
If Target.Offset(0, 2).Value <> Empty Then
If Left(Target.Value, 1) = Target.Offset(0, 2).Value Then
Target.Offset(0, 3).FormulaR1C1 = "Formula A"
Else
Target.Offset(0, 3).FormulaR1C1 = "Formula B"
End If
End If
End If
End Sub

Regards
Rowan
 

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