+ Reply to Thread
Results 1 to 8 of 8

How to extract strings before and after (-) dashes --- macro

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    How to extract strings before and after (-) dashes --- macro

    I am writing to seek help, in updating the following macro code below, so it can read any strings in column F, before the dashes and display the output in column G. However if Column F has a string (J-), then take number after dash.

    Please advice, as I am little unsure how to go about updating this.

    I have attached sample data in the attachment, and shows highlighted strings which the code is currently not translating.
    Please note the code is behind 'sheet1', for further reference.
    Book1.xlsm


    Please Login or Register  to view this content.

    Desired output in column G
    J+34 --> 34
    J-67 --> 67

    Many Thanks for your time and help.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: How to extract strings before and after (-) dashes --- macro

    The attached code works on the sample.
    Attached Files Attached Files
    Last edited by AB33; 06-11-2014 at 11:06 AM.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to extract strings before and after (-) dashes --- macro

    Hi missy22,

    Try:
    Please Login or Register  to view this content.

    To prevent typos from ruining days and weeks of work you need 'Option Explicit' at the top of each code module. This forces you to declare every variable. See http://www.cpearson.com/excel/DeclaringVariables.aspx

    Lewis

  4. #4
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: How to extract strings before and after (-) dashes --- macro

    Hi, thanks for your response, but I am sorry to inform, that I could not get workbook above to work, as both sheet1 and sheet1(2), had the same code behind and was unable to produce the desired output in column G,such as:
    J+34 --> 34
    J-67 --> 67

    Please advice, many thanks.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,575

    Re: How to extract strings before and after (-) dashes --- macro

    Please Login or Register  to view this content.
    Last edited by jindon; 06-11-2014 at 11:07 AM.

  6. #6
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    Re: How to extract strings before and after (-) dashes --- macro

    Dear LJMetzger,

    thank you for your reply. I am sorry to inform, I tested your code but I am still experiencing the same issue, as the code is failing to convert the strings correctly.

    Desired output:
    45-45-->45
    J+34-->34
    S+908-89--> S+908
    J-67 -->67


    I have updated my code using code, the attachment below.
    Book3.xlsm

    Please advice further, if possible. many thanks.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,575

    Re: How to extract strings before and after (-) dashes --- macro

    Quote Originally Posted by missy22 View Post
    Desired output:
    45-45-->45
    J+34-->34
    S+908-89--> S+908
    J-67 -->J in your attached file
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: How to extract strings before and after (-) dashes --- macro

    Hi again,

    I had to move the following code a little. Please try again. If you still have problems, please let me know.

    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

+ 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. Replies: 3
    Last Post: 01-17-2014, 08:08 PM
  2. [SOLVED] Extract strings from first dot find..???
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-18-2013, 11:16 PM
  3. Macro to extract strings between key words
    By aillil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2013, 09:51 AM
  4. Extract specific strings within a cell macro
    By ardniw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2013, 03:41 AM
  5. Reading in Number Strings with Dashes in SUMPRODUCT
    By rackun in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-23-2008, 01:50 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