PDA

View Full Version : [SOLVED] Remove Text



ldperrotta
03-27-2014, 08:05 PM
Sub DelLeft()
Dim l as long, d as long
l = Len(Selection)
d = InStr(1, Selection, " ")
If Not d = 0 Then Selection.Offset(, 1) = Right(Selection, l - d)
End Sub



****************
I've been looking for hours for some macro help that does just this EXCEPT that it only works when I select one cell at a time. I need to select many cells. I can't figure out what the limitation is here. When I select more than one cell and run the macro, I get Run-time error 13, Type Mismatch. The Debugger highlights this line: l = Len(Selection)

Is this code intended to work for one cell at a time?

I know just enough to be dangerous with macros but have been helped tremendously thus far by the experts here. Thank you.

jonh
03-28-2014, 03:23 AM
check each cell in the range


Sub TxtTrim()
For Each c In Selection
i = InStr(c.Value, " ")
If i Then c.Value = Mid(c.Value, i + 1)
Next
End Sub

ldperrotta
03-28-2014, 06:36 AM
check each cell in the range


Sub TxtTrim()
For Each c In Selection
i = InStr(c.Value, " ")
If i Then c.Value = Mid(c.Value, i + 1)
Next
End Sub

Thank you, this appears to work perfectly!!

Happiness is...getting your VB code to work!