Consulting

Results 1 to 3 of 3

Thread: Remove Text

  1. #1

    Remove Text

    Quote Originally Posted by mdmackillop View Post
    [vba]
    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

    [/vba]
    ****************
    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.

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    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

  3. #3

    Smile Works!

    Quote Originally Posted by jonh View Post
    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!

Posting Permissions

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