Consulting

Results 1 to 4 of 4

Thread: How to trim a string from both sides?

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location

    How to trim a string from both sides?

    Hello people

    I got this string "2015-07-22"

    but I just want to have 07

    Could someone help me with a code?

    Thank you in advance

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    This is how I arrived at a solution but then I tend to do things backwards.... Assuming the string is in A1 and formula is in A2

    =Right(Left(A1,7), 2)

    Others though would use the Mid function

    =Mid(A1,6,2)

    Which Excel would prefer.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Looks very much like a date.
    =MONTH(A1)


    If it is text, try
    =TRIM(MID(SUBSTITUTE(A1,"-",REPT(" ",999)),999,999))
    Where you have "07", it can be any length between "-"'s

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If it is a date, then use =Text in a UDF or Format() in a VBA solution. For the former: =TEXT(A1, "MM")

Tags for this Thread

Posting Permissions

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