+ Reply to Thread
Results 1 to 5 of 5

VBA to remove characters from a string

  1. #1
    Registered User
    Join Date
    02-26-2015
    Location
    Weymouth, Dorset
    MS-Off Ver
    2007
    Posts
    14

    VBA to remove characters from a string

    Hi

    I have a workbook which contains addresses, but has been formatted in a bit of an odd way. The original format is along the lines of "Flat 1, 145, Any Street ¦PC1_1PC" in a single cell. I have successfully separated the post code (for non-English readers, that's the part after the ¦), reomved the underscore and put it in a separate cell.

    However, I need to remove the spaces and the ¦ from the "address" part. Unfortunately, the number of spaces varies, as does the number of characters in the address. I am now stuck trying to work out how to do this - I think I need to do something with the LEN of the string, but how do I find the number of characters (I can't just count spaces as tehre will be a varied number of spaces within the actual address).

    Any help much appreciated.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: VBA to remove characters from a string

    Hi,

    Does this get you started?

    =SUBSTITUTE(LEFT(A1,FIND("¦",A1)-1)," ","")
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to remove characters from a string

    Maybe?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA to remove characters from a string

    If none of the above suggestions work for you, submit an example workbook with a couple of before and after examples.

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: VBA to remove characters from a string

    As a last resort you could try saving the file as a csv file as this is a “flat file” with no formatting.

    Then import the file back into excel and see if things have improved.

    Alf

+ 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] VBA, remove all characters within a string, except numerical characters and full stops
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2015, 09:24 PM
  2. [SOLVED] VBA Remove First 10 Characters From string
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2013, 08:22 AM
  3. [SOLVED] Remove certain characters from the end of a string only
    By mini_dutch28 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-20-2012, 01:04 PM
  4. Remove characters in a string.
    By jncswe in forum Excel General
    Replies: 2
    Last Post: 09-10-2010, 07:26 AM
  5. Remove Characters From Right of String
    By milagros in forum Excel General
    Replies: 11
    Last Post: 12-26-2009, 12:01 PM

Tags for this Thread

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