+ Reply to Thread
Results 1 to 8 of 8

Remove last character of string does not work

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Question Remove last character of string does not work

    Hello,

    I have a macro that generates a string from cell values in cell A4:A999, and seperates them by comma. This works great, but leaves a comma at the end.
    I found a solution to removing the comma, but now (after about one week) it does not work anymore.

    This is my code:
    Please Login or Register  to view this content.
    The value pasted in cell I1 is: 3,05860230587633E+300 instead of what i want which is: 3058602,3058763,3059968 etc. Looks like the code removes ALL commas, instead of just the last one.

    Any help? As mentioned, it worked for a week.
    Last edited by vonrainer; 07-10-2014 at 03:21 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: Remove last character of string does not work

    try removing the two "$" in the error line
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Re: Remove last character of string does not work

    Tried removing the two "$", but still the same result. It removes all commas in the string, not just the last one

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Remove last character of string does not work

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Remove last character of string does not work

    Hi, vonrainer,

    I would not recommend to use a comma or a point as separator when working with numbers. What happens if you exchange the comma with the pipe sign (|)?

    Besides: the code itself will not remove any characters, maybe itīs VBA/Excel which dioes so. And maybe you should alter the code to show the proper tyoe of teh variables that you will use (Option Explicit could be very annoying at the start but proove to be really helpful).

    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Re: Remove last character of string does not work

    Hi Holger,

    The thing is, I need to use comma to separate the numbers. The string generated is used as a querry string on a SQLdb.
    If I use this code:
    Please Login or Register  to view this content.
    The value pasted in cell I1 is the correct format (3061549, 3061548 etc). For the SQL to accept the string, I need to remove the last comma (30061549,)
    The code worked for a week, and made this:
    Please Login or Register  to view this content.
    into this:
    Please Login or Register  to view this content.
    Note the last comma is gone.

    Is it perhaps possible to make a new script to remove the last character in cell I1, and make this run after the string is generated and pasted in the cell? Would this possibly be easier?

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Remove last character of string does not work

    Hi, vonrainer,

    some alternatives. Try using the conversion to a string like
    Please Login or Register  to view this content.
    See if SQL is accepting a leading apostrophe like
    Please Login or Register  to view this content.
    Remove the last character when passing the string to SQL. If this is written in VBA code use the pipe sign for the concatening and read the value into a variable and replace the charcters there to see if this would work.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Re: Remove last character of string does not work

    Holger, you are a life-saver!

    Adding the "'" before printing the string in cell I1 worked. The sql accepted the string. My full code is now as follows, changes marked in red:
    Please Login or Register  to view this content.

+ 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. [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
  2. Remove last word/character from a string
    By Delkath in forum Excel General
    Replies: 3
    Last Post: 09-08-2010, 01:48 PM
  3. Remove Last Character from String
    By SLP in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2007, 05:17 PM
  4. remove special character at end of string
    By captain bob in forum Excel General
    Replies: 0
    Last Post: 08-03-2006, 09:59 AM
  5. Replies: 5
    Last Post: 08-29-2005, 11:05 PM

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