• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to delete last character in cell....conditionally

umpscott

New Member
I would like to create vba code to remove the last character in a cell, but only in the case that the last character is a ~. It is ok for the ~ character to occur elsewhere, just not as the last character.

Thanks in advance.
 
Hi, umpscott!

Tried with something like this?
Code:
    With ActiveCell
        If Right(.Value, 1) = "~" Then .Value = Right(.Value, Len(.Value) - 1)
    End With

Regards!
 
Hi, umpscott!

Tried with something like this?
Code:
    With ActiveCell
        If Right(.Value, 1) = "~" Then .Value = Right(.Value, Len(.Value) - 1)
    End With

Regards!

I like this thought..... but here is what I tried.

I would like to do this to multiple cells in a particular column (Field)

Code:
Range("DataTable[Pred_Description]").Select
  With Selection
  If Right(.Value, 1) = "~" Then .Value = Right(.Value, Len(.Value) - 1)
  End With
 
Hi, umpscott!

And what about this?
Code:
    Dim c As Range
    For Each c In Range("DataTable[Pred_Description]")
        With c
            If Right(.Value, 1) = "~" Then .Value = Right(.Value, Len(.Value) - 1)
        End With
    Next c

Regards!
 
Thanks SirJB7...... I had to make one change. I replaced second RIGHT with a LEFT, as the result was cutting off the first character.

Code:
Dim c As Range
  For Each c In Range("DataTable[Pred_Description]")
  With c
  If Right(.Value, 1) = "~" Then .Value = Left(.Value, Len(.Value) - 1)
  End With
  Next c
 
Hi, umpscott!
Yes, my mistake, you're right.
Glad you solved it. Thanks for your feedback and welcome back whenever needed or wanted.
Regards!
 
Back
Top