+ Reply to Thread
Results 1 to 14 of 14

Extract a portion from string

  1. #1
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Extract a portion from string

    I have a string like 1234 x 4566 x 34cm x 1245666cm I get this value from excel cell and put it into variable then I want to get the value from 1 to x and then from next x to x and similarly..
    I want to this
    dim a as integer
    dim b as integer
    dim cellval as string
    cellval = get the cell value
    now I want this but get error
    a=instr(cellval,'x')-------first x
    b=instr(cellval,'x') =---------second x
    msgbox Mid(cellval,a,b)-------------------------but get error....

    how I can put MID(cellval,'herer instead of 1,2,3 I want to put variable')

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a portion from string

    Hi, welcome to he forum

    You need to show us what you expect, not just some code that doesnt work

    What should your answer look like?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    simply I need only split the string as I mentioned. using MID(string,here I want to put the variable instead of integer....)

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a portion from string

    I ask again, what would your expected answer look like? If I knew what you wanted, I would not have asked

  5. #5
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    108 9/16 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm
    8 1/8 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm
    these are column value exist in single col now I want to convert these value as
    108.5625x 59.25 x 1.75 inches 275.7 x 150.5 x 4.5 cm

    just conver each fraction into decimal and append in exact that place.whether these is using vba or simple excel formula

  6. #6
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    Or Simply divide the below cell value into three parts on the basis of x
    108 9/16 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm
    such one col split into three as
    col1 col2 col3
    108 9/16 59 1/4 1 /3/4
    How we can do it but the 108 9/16 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm is in variable and then in the variable we should split it.

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Extract a portion from string

    maybe something like this
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    thx nilem for your reply.
    yes its works actually i a whole column which contain such value , i want after doing the above working converting the fraction into decimal then join the string in such manner as 108.5625 x 59.25 x 1.75 inches.........
    how i can do this?

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract a portion from string

    As I understand you only need to convert the first part of the string. Here is a formula solution
    Enter in B1 and copy across to cell D1 and then down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B C D
    1 108 9/16 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm 108.5625 59.25 1.75
    2 8 1/8 x 59 1/4 x 1 3/4 inches 275.7 x 150.5 x 4.5 cm 8.125 59.25 1.75
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Extract a portion from string

    or maybe so
    Please Login or Register  to view this content.
    Last edited by nilem; 05-06-2016 at 11:09 AM. Reason: Wow, 3,000 posts :)

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extract a portion from string

    I was going to go the same way AlKey went, but he beat me to it

  12. #12
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    great its works thx to all expert

  13. #13
    Registered User
    Join Date
    05-05-2016
    Location
    pakistan
    MS-Off Ver
    2007
    Posts
    7

    Re: Extract a portion from string

    can anyone get me an idea about it
    x 12.3 x 23.4 x 4.5
    in each cell i have x in starting i want to remove the starting x in each row of cell
    as 12.3 x 23.4 x 4.5

  14. #14
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract a portion from string

    Try this
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 x 12.3 x 23.4 x 4.5 12.3 x 23.4 x 4.5

+ 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. How to extract a portion of URL and merge it with a string
    By emymeeky in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-09-2015, 11:39 AM
  2. Matching specific portion of a string and retrieving the whole string
    By mellowtang in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-27-2015, 07:06 AM
  3. [SOLVED] Need to extract TWO portion until special character
    By K.T in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-13-2012, 12:57 PM
  4. [SOLVED] How do I extract a portion of a string into an adjacent cell?
    By tura910 in forum Excel General
    Replies: 4
    Last Post: 03-26-2012, 08:40 AM
  5. Formula to extract a portion or url
    By maheshr68 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2012, 02:20 PM
  6. Extract right portion of a formula
    By jeffreybrown in forum Excel General
    Replies: 8
    Last Post: 12-24-2011, 10:20 AM
  7. Extract a specific portion of a text string in Excel?
    By drawkcaB in forum Excel General
    Replies: 3
    Last Post: 05-18-2010, 01:48 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