VBA to extract first two characters from a string

  • I am sure this is a simple one, but I'm foxed...


    I am working with a stored string in VBA, and I would like to 'capture' the first two characters of that string, and store them to memory as a separate string.


    Can anyone help?

  • Re: VBA to extract first two characters from a string


    Hi


    Use the left function


    see eg below


    Code
    Sub strmac()
    Dim a As String
    a = Sheets("sheet1").Range("b4")
    a = Left(a, 2)
    Sheets("sheet1").Range("f1") = a
    End Sub


    pangolin

  • Re: VBA to extract first two characters from a string


    Thanks Will & Ivan (seeing as you both submitted at the same time with an identical response :)


    This works just grand! I knew it would have been something simple!!!


    Regards,
    Damian

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!