Consulting

Results 1 to 5 of 5

Thread: Solved: If 8th character ...then

  1. #1

    Solved: If 8th character ...then

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    If Mid$(variable_name,8,1) = "P" Then
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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

  4. #4
    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

  5. #5
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    [VBA]
    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
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •