PDA

View Full Version : [SOLVED] Break text



Romulo Avila
01-12-2018, 04:45 AM
Good Morning,

I have some data below

A1 -> TEST - 123 - 965A

A2 -> TEST - 111 - 656 - 965ASD

I need to break it so it looks like this

B1 -> 965A
B2 -> 965ASD

I need to fetch the 20 characters after the last "-"

Can be VBA or formula.

mana
01-12-2018, 04:58 AM
Option Explicit


Sub test()
Dim c As Range
Dim s


For Each c In Columns(1).SpecialCells(2)
s = Split(c.Value, "-")
c.Offset(, 1).Value = s(UBound(s))
Next

End Sub

SamT
01-12-2018, 11:00 AM
Good code, mana.
But I would use spaces around the dash in the Split parameter

s = Split(c.Value, " - ")

Or Trim the return

s = Trim(Split(c.Value, "-"))

Probably best to Trim the return so some typo leaving out the Space won't kill the code.

Romulo Avila
01-12-2018, 11:32 AM
Good afternoon,


Thank you very much, it was very good.