+ Reply to Thread
Results 1 to 5 of 5

Deleting last letter if a cell

Hybrid View

  1. #1
    Kevin O'Neill
    Guest

    Deleting last letter if a cell

    What I'd like to do is, if the last letter of what is inputed into a
    cell is the "+" symbol. Then delete it.


    I have a cell defined by:
    Sheet12.Cells(11, 2) = d & "+" + l & "+" + w & "+" + s


    Here's what i get fromt that cell.
    ..5D + 2L + 3W + 2S


    if i change it and s = 0 i get
    ..5D + 2L + 3W +


    i want to get
    ..5D + 2L + 3W


    So i was hoping maybe there was a command, to delete a space off the
    end of a cell using and IF statement.


    IF last letter is a "+" , delete 1-2 spaces of the end of the cell.


  2. #2
    Kevin O'Neill
    Guest

    Re: Deleting last letter if a cell

    Suppose to be titled

    "Deleting last letter OF a cell"


  3. #3
    Tom Ogilvy
    Guest

    Re: Deleting last letter if a cell

    right click on the sheet tab and select view code

    in the left dropdown at the top of the resulting module, select
    WorkSheet
    and in the right dropdown select
    Change (not SelectionChange)

    then put code in this sub (the change event) like this

    Dim s as String
    If Target.count > 1 then exit sub
    if isempty(target) then exit sub
    if Target.Column = 2 then
    s = Trim(Target.Value)
    if Right(s,1) = "+" then
    Application.enablevents = False
    Target.Formula = Trim(Left(s,len(s)-1))
    Application.EnableEvents = True
    end if
    end if


    as written works only in column B. Change to suit

    --
    Regards,
    Tom Ogilvy






    "Kevin O'Neill" <ire.kevin@gmail.com> wrote in message
    news:1132347651.940501.59150@g47g2000cwa.googlegroups.com...
    > Suppose to be titled
    >
    > "Deleting last letter OF a cell"
    >




  4. #4
    Kevin O'Neill
    Guest

    Re: Deleting last letter if a cell

    Ah Aswome guys got that working good. There's that other tricky part,
    which I think will actually be tricky.

    If my result is:
    ..5D + .5L + 2S

    convert that to:
    ..5(D+L) +2S

    What do you think?


  5. #5
    Dave Peterson
    Guest

    Re: Deleting last letter if a cell

    dim myStr as string

    mystr = ".5D + 2L + 3W + "
    'extra spaces, too

    mystr = trim(mystr) 'gets rid of leading and trailing spaces

    if right(mystr,1)="+" then
    mystr = trim(left(mystr,len(mystr)-1))
    'also cleans up trailing spaces with the trim.
    end if

    msgbox "***" & mystr & "***"



    Kevin O'Neill wrote:
    >
    > What I'd like to do is, if the last letter of what is inputed into a
    > cell is the "+" symbol. Then delete it.
    >
    > I have a cell defined by:
    > Sheet12.Cells(11, 2) = d & "+" + l & "+" + w & "+" + s
    >
    > Here's what i get fromt that cell.
    > .5D + 2L + 3W + 2S
    >
    > if i change it and s = 0 i get
    > .5D + 2L + 3W +
    >
    > i want to get
    > .5D + 2L + 3W
    >
    > So i was hoping maybe there was a command, to delete a space off the
    > end of a cell using and IF statement.
    >
    > IF last letter is a "+" , delete 1-2 spaces of the end of the cell.


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1