PDA

View Full Version : Solved: If 8th character ...then



blackie42
08-28-2009, 02:43 AM
Hi,

I'm wanting to create an if/then statement in VBA and would like to test if
the 8th character in a string of 9 (mixed numbers & text) is a 'P'

Any help appreciated

thanks

Bob Phillips
08-28-2009, 03:07 AM
If Mid$(variable_name,8,1) = "P" Then

blackie42
08-28-2009, 03:18 AM
Hi Bob,

thanks for reply - I think I may have misled you a bit.

I have a cell (M2) where a policy number is captured and if the policy numbers (which is in the format NNNNNNNLN) 8th character is a 'P' and
the value of another cell (V20) is below 2.5 then I want to do some other stuff. (And if its above 2.50 I wan to do some different stuff)

cheers

blackie42
08-28-2009, 03:22 AM
However it does seem to work by replacing 'variable_name' with Range("M2").

Need to test ot a little more but thanks again

regards

Jon

MaximS
08-29-2009, 04:58 AM
If Mid(Range("M2").Value, 8, 1) = "P" Then
If Range("V20").Value > 2.5 Then
'do stuff
Else
'do other stuff
End If
End If