ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   comparing text in if statement (https://www.excelbanter.com/excel-programming/337667-comparing-text-if-statement.html)

Dolemite[_3_]

comparing text in if statement
 

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.


--
Dolemite
------------------------------------------------------------------------
Dolemite's Profile: http://www.excelforum.com/member.php...o&userid=26136
View this thread: http://www.excelforum.com/showthread...hreadid=396993


Rowan[_2_]

comparing text in if statement
 
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

"Dolemite" wrote:


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.


--
Dolemite
------------------------------------------------------------------------
Dolemite's Profile: http://www.excelforum.com/member.php...o&userid=26136
View this thread: http://www.excelforum.com/showthread...hreadid=396993




All times are GMT +1. The time now is 10:55 AM.

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