Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you do an IF statement in Excel comparing three columns JB Excel Worksheet Functions 1 February 2nd 10 05:04 PM
If statement comparing times GoBrowns! Excel Worksheet Functions 1 June 17th 09 02:33 PM
Comparing 2 text cells in an if statement wrkingurl Excel Discussion (Misc queries) 3 March 24th 09 03:27 PM
Comparing Model Numbers without a giant IF statement Shawn Conn Excel Worksheet Functions 2 June 12th 08 01:30 PM
IF statement comparing month and year separately spence Excel Worksheet Functions 6 April 26th 07 10:47 PM


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"