View Full Version : [SOLVED:] How to trim a string from both sides?
elmnas
07-29-2015, 12:07 AM
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
Aussiebear
07-29-2015, 12:29 AM
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.
jolivanes
07-29-2015, 12:04 PM
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
Kenneth Hobs
07-29-2015, 12:15 PM
If it is a date, then use =Text in a UDF or Format() in a VBA solution. For the former: =TEXT(A1, "MM")
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.