PDA

View Full Version : Solved: Delete number of characters from string



ulfal029
01-11-2008, 03:38 AM
I'm looking for a way to delete 7 characters, starting from right, from a string in a cell:

TEST 2 xxxxxxx
to
TEST 2

The total number of characters may vary, but keep all except the 7 ones starting from right.

Label1.Caption = Range("A2")....?

Thank you.

Bob Phillips
01-11-2008, 03:48 AM
With Range("A2")
Label1.Caption = Left$(.Value, Len(.Value) - 7)
End With

Bob Phillips
01-11-2008, 03:51 AM
Thinking about it, this might suit more



With Range("A2")
Label1.Caption = Left$(.Value, InstrRev(.Value," "))
End With

ulfal029
01-11-2008, 04:50 AM
They both worked; thanks a lot!

Bob Phillips
01-11-2008, 04:54 AM
The second is more generic though, as it will delete how ever many characters after the last space.