Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Partial String Recognition 1

Status
Not open for further replies.

Bass71

MIS
Jun 21, 2001
79
0
0
Hi:

I need to evaluate only part of a text string. Is there a function that evaluates only part of a string and if that condition is met, then it triggers the "then" of my if-then statement?

Ex:

Dim Jan As Date
Jan = DateValue("1/1")
If ActiveCell.Value = "January" Then
ActiveCell(2, 8).Value = Jan

<<In the cell that's being evaluated, there are numbers after the &quot;January&quot;, so I need the condition to be satisfied when the word January, alone, is evaluated.

Thanks for your help...................


 
You can use the Like operator to check your string.

If MyString Like &quot;*January*&quot; Then
'Execute code
End If

HTH
Joe Miller
joe.miller@flotech.net
 
How about using the mid function. Mid(expression, start, length). So you would put your expression, the character you want to start with, and how far over you want to go. The following assumes that you are starting at character 1, but you could start anywhere in the string.

Example:


if mid(activecell.value, 1, 7) = &quot;january&quot; then
activecell(2,8).value = jan
else
activecell(2, 8).value = &quot;&quot;
end if

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top