Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default IF statement that looks at part of the contents of a cell.

I have a need to make decisions based on the content of a cell that
contains an alphanumeric string such as P8072A. I want the ability to
look at this cell and take an action based on what the first letter in
the string is. For example, If the string is P8072A, I want cell G5 to
be 2.5, and if the string is Y2898B then I want cell G5 to be 3.0
(because the first letter changed from P to Y). Is there a way to have
excel look at letters in a cell to make logical decisions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default IF statement that looks at part of the contents of a cell.

I think I may have it.... =IF(MID(C10,1,1)="P","True","False")
MID returns the first character in cell C10. I compare it to "P" and it
gives a true or false.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default IF statement that looks at part of the contents of a cell.

Hi Jon,

'=============
Public Sub TestIt()
Dim Rng As Range
Dim rcell As Range

Set rcell = Range("A1") '<<==== CHANGE

If FirstAlpha(rcell.Value) = "P" Then
Range("G5").Value = 2.5
ElseIf FirstAlpha(rcell.Value) = "Y" Then
Range("G5").Value = 3
Else
'do something else?
End If
End Sub

'-----------------

Public Function FirstAlpha(sStr As String)
Dim Re As Object

Set Re = CreateObject("VBScript.RegExp")
Re.IgnoreCase = True
Re.Global = True
Re.Pattern = "\d"

FirstAlpha = Left(Re.Replace(sStr, vbNullString), 1)

End Function
'<<=============


---
Regards,
Norman



"Jon" wrote in message
oups.com...
I have a need to make decisions based on the content of a cell that
contains an alphanumeric string such as P8072A. I want the ability to
look at this cell and take an action based on what the first letter in
the string is. For example, If the string is P8072A, I want cell G5 to
be 2.5, and if the string is Y2898B then I want cell G5 to be 3.0
(because the first letter changed from P to Y). Is there a way to have
excel look at letters in a cell to make logical decisions?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default IF statement that looks at part of the contents of a cell.

if left(activecell,1) = "P" then

elseif left(activecell,1) = "Y" then

end if

--
Regards,
Tom Ogilvy


"Jon" wrote in message
oups.com...
I have a need to make decisions based on the content of a cell that
contains an alphanumeric string such as P8072A. I want the ability to
look at this cell and take an action based on what the first letter in
the string is. For example, If the string is P8072A, I want cell G5 to
be 2.5, and if the string is Y2898B then I want cell G5 to be 3.0
(because the first letter changed from P to Y). Is there a way to have
excel look at letters in a cell to make logical decisions?



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
Looking Up Part Cell Contents Steve Excel Discussion (Misc queries) 2 April 22nd 09 05:20 PM
#N/A if cell contents not part of an array MichaelR Excel Discussion (Misc queries) 5 June 28th 08 03:09 AM
Combining Cell Contents (Part 2) PaolaAndrea Excel Discussion (Misc queries) 3 May 9th 08 08:10 PM
Can I use cell contents as part of a formula? Brian Rhodes Excel Worksheet Functions 3 June 3rd 05 05:00 PM
Web query - using cell contents as part of URL claytorm[_2_] Excel Programming 1 July 29th 04 04:16 PM


All times are GMT +1. The time now is 04:15 PM.

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

About Us

"It's about Microsoft Excel"