+ Reply to Thread
Results 1 to 4 of 4

Check string variable and remove last character if it's a comma

  1. #1
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 2016
    Posts
    260

    Check string variable and remove last character if it's a comma

    Hi all,

    I have inherited a spreadsheet with VBA code that dynamically creates a string from various bits of dynamic text scattered around the workbook. Sometimes though it ends the constructed sentence with a comma and I need it to remove this if this is the case. Pseudo-code would be

    1) Create string (this bit works okay)
    2) Check last character - is it a comma?
    3) If so remove last character, else do nothing

    I've tried various approaches but can't get it to work. Anyone got any suggestions???

    Thanks

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Check string variable and remove last character if it's a comma

    Try
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Check string variable and remove last character if it's a comma

    I don't know how you want to use (events or run macro manually).
    For manual:

    Please Login or Register  to view this content.
    for worksheet_change event replace cell.value for target.value without loop.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  4. #4
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 2016
    Posts
    260

    Re: Check string variable and remove last character if it's a comma

    Cheers guys got it working now :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Aloha need to remove the last character in a string if it is a comma
    By OahuBrew in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-13-2013, 04:52 PM
  2. [SOLVED] Remove the first character only if it is a comma
    By Pearlyn in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-02-2013, 10:17 AM
  3. check to see if the first character in a string is a comma
    By pablowilks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2012, 03:52 PM
  4. [SOLVED] Remove last character from string and sum product
    By ABSTRAKTUS in forum Excel General
    Replies: 3
    Last Post: 04-03-2012, 10:46 AM
  5. Remove last word/character from a string
    By Delkath in forum Excel General
    Replies: 3
    Last Post: 09-08-2010, 01:48 PM
  6. How Remove Comma in the first character
    By antoni in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2009, 01:31 AM
  7. Remove Last Character from String
    By SLP in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2007, 05:17 PM
  8. [SOLVED] find and remove a string of a cell value with comma as delimiter
    By yefei in forum Excel General
    Replies: 3
    Last Post: 02-28-2006, 09:10 AM

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