+ Reply to Thread
Results 1 to 18 of 18

VBA Code to extract Text btwn ">TEXT<" ?

  1. #1
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    VBA Code to extract Text btwn ">TEXT<" ?

    Anyone care to share VBA code to extract out Text btwn ">TEXT<" on Col G of my worksheet ?

    Below some examples of Case scenarious:

    Input: <p><strong><span>Size</span></strong></p> <p><strong><span>39*45*H(80-104)CM</span></strong></p>
    Output: 39*45*H(80-104)CM

    Input: <p><span style="font-family: Arial; font-size: small;"><span style="color: #000000; font-family: Arial; font-size: x-small;">X-style height adjustable keyboard/piano bench. </span></span>
    Output: X-style height adjustable keyboard/piano bench.

    Input: <span style="font-size: x-small;"> Generous sized 60 cm x 32 cm</span></span>
    Output: Generous sized 60 cm x 32 cm

    Input: <span style="font-size: x-small;"> Generous sized 60 cm x 32 cm</span></span><span style="font-family: Arial; font-size: x-small;"> seat. </span>Black finish.</p>
    Output: Generous sized 60 cm x 32 cm. seat. Black finish.

    What to look for: >TEXT< AND omit ><

    Note: Each Cell can have "multiple" instances of ">TEXT<" (in a single cell), as shown on Case Scenario #4

    Thanks in Advance.
    Last edited by mave27; 08-04-2015 at 05:17 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Please Login or Register  to view this content.
    Although for 1st example the result is,
    Size 39*45*H(80-104)CM
    Cheers
    Andy
    www.andypope.info

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

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    ......................
    Last edited by jindon; 08-04-2015 at 06:43 AM.

  4. #4
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    Please Login or Register  to view this content.
    Although for 1st example the result is,
    Size 39*45*H(80-104)CM
    Looks good, havent test it yet.

    Just curious - i dont see anywhere in the code which Col it's referencing ? The data that needs cleaning up is on Col G. Can I get the output to Col H ?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    The example just uses the active cell as input and outputs to immediate window.
    You would need to specify in the code what cells it should be used on and where the result goes.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    The example just uses the active cell as input and outputs to immediate window.
    You would need to specify in the code what cells it should be used on and where the result goes.

    Please Login or Register  to view this content.
    Andy - thanks, thanks, thanks !!! Works like a magic wand !!

  7. #7
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    The example just uses the active cell as input and outputs to immediate window.
    You would need to specify in the code what cells it should be used on and where the result goes.

    Please Login or Register  to view this content.
    Andy - the Function is working fine.

    Do you mind tweaking the code to remove all instances of &nbsp; ?

    Example:

    Input: <p>KW 18 8x21DCF &nbsp;POWERVIEW Folding Series 383ft/1000yds 128m/1000m with case</p>
    Output: KW 18 8x21DCF POWERVIEW Folding Series 383ft/1000yds 128m/1000m with case

    Note: there can be multiple instances of &nbsp; in any given cell data.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    change the last line of the function

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    change the last line of the function

    Please Login or Register  to view this content.
    Thanks.

    I've noticed some other bits of Text that i don't want like &amp;

    What would be the modified code to incorporate any additional text to omit ?

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Please Login or Register  to view this content.
    You can add items to the Array list

  11. #11
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    Please Login or Register  to view this content.
    You can add items to the Array list
    New code is giving an Error of #VALUE!

    PS: i have changed code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    to reflect the range on my worksheet

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    hard to say without seeing what the contexts of the cell are

    The code works for the examples you have provided so far

  13. #13
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by Andy Pope View Post
    hard to say without seeing what the contexts of the cell are

    The code works for the examples you have provided so far
    Do you mind running the latest modified code for Input Value:

    <h2><span style="text-decoration: underline; color: #ff0000;">GATE VALVE LOCKOUT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></h2> <table border="0" cellspacing="0" cellpadding="0" width="755"> <tbody> <tr> <td width="490" valign="top"> <ul> <li>Virtually indestructible valve covers.</li> <li>Once locked, they rotate freely around the hand wheel &amp; prevent the valve wheel from being turned.</li> <li>The strong polyurethane plastics make them resistant to cracking and abrasion.</li> <li>They are resistant to extreme weather and temperature conditions.</li> <li>Available in&nbsp;<strong>5 sizes ( Red colour )&nbsp;</strong>Other colours are available on request - minimum quantity applicable.</li> <li>3 padlock holes are available in each gate valve lockout device.</li> <li>Different sizes cover most commonly used valve diameters.</li> <li>Withstands temperatures from - 20&deg;F to 200&deg;F</li> <li>Unique knockout center accommodates OS &amp; Y or &ldquo;rising stem&rdquo; valves.</li> <li>Suitable for hasps and padlocks.</li> </ul> <table border="0" cellspacing="0" cellpadding="0" width="435"> <tbody> <tr> <td class="tblHeaderLeft1" colspan="6">&nbsp;&nbsp;&nbsp; <strong>Dimensions</strong></td> </tr> <tr> <td class="tbBlack"><span style="color: #ff0000;">Size</span></td> <td class="tbBlack"><span style="color: #ff0000;">Inside dia (A)</span></td> <td class="tbBlack"><span style="color: #ff0000;">Inside depth.(B)</span></td> <td class="tbBlack"><span style="color: #ff0000;">Outside dia. (C)</span></td> <td class="tbBlack"><span style="color: #ff0000;">Outside height (D)</span></td> </tr> <tr> <td class="tbWhite">25 - 63.5 mm</td> <td class="tbWhite">70 mm</td> <td class="tbWhite">32 mm</td> <td class="tbWhite">76 mm</td> <td class="tbWhite">38 mm</td> </tr> <tr> <td class="tbWhite">63.5 - 127 mm</td> <td class="tbWhite">130 mm</td> <td class="tbWhite">34 mm</td> <td class="tbWhite">140 mm</td> <td class="tbWhite">44 mm</td> </tr> <tr> <td class="tbWhite"><span style="background-color: #ffff00;">127 - 165 mm</span></td> <td class="tbWhite"><span style="background-color: #ffff00;">170 mm</span></td> <td class="tbWhite"><span style="background-color: #ffff00;">41 mm</span></td> <td class="tbWhite"><span style="background-color: #ffff00;">177 mm</span></td> <td class="tbWhite"><span style="background-color: #ffff00;">50 mm</span></td> </tr> <tr> <td class="tbWhite">165 - 254 mm</td> <td class="tbWhite">257 mm</td> <td class="tbWhite">50 mm</td> <td class="tbWhite">267 mm</td> <td class="tbWhite">63 mm</td> </tr> <tr> <td class="tbWhite">254 - 355 mm</td> <td class="tbWhite">355 mm</td> <td class="tbWhite">63 mm</td> <td class="tbWhite">368 mm</td> <td class="tbWhite">74 mm</td> </tr> </tbody> </table> <br /> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="tblHeaderLeft"><strong>MODEL</strong></td> <td class="tblHeaderRight"><strong>PRODUCT DESCRIPTION</strong></td> </tr> <tr> <td class="tblHeaderLeftcode"><span style="color: #000000;">ES -<strong>&nbsp;02 - GVL</strong></span></td> <td class="tblHeaderRightcode"><span style="color: #000000;">Fits on handle wheel dia from 25 to 63.5 mm ( 1" - 2½" inch)</span></td> </tr> <tr> <td class="tblHeaderLeftcode">ES -<strong>&nbsp;04 - GVL</strong></td> <td class="tblHeaderRightcode">Fits on handle wheel dia from 63.5 to 127 mm ( 2½" - 5" inch)</td> </tr> <tr> <td class="tblHeaderLeftcode"><span style="background-color: #ffff00;">ES -<strong>&nbsp;06 - GVL</strong></span></td> <td class="tblHeaderRightcode"><span style="background-color: #ffff00;">Fits on handle wheel dia from 127 to 165 mm ( 5" - 6½" inch)</span></td> </tr> <tr> <td class="tblHeaderLeftcode">ES -<strong>&nbsp;08 - GVL</strong></td> <td class="tblHeaderRightcode">Fits on handle wheel dia from 165 to 254 mm ( 6½" - 10" inch)</td> </tr> <tr> <td class="tblHeaderLeftcode">ES -<strong>&nbsp;10 - GVL</strong></td> <td class="tblHeaderRightcode">Fits on handle wheel dia from 254 to 355 mm ( 10" - 13" inch)</td> </tr> </tbody> </table> </td> <td width="260" valign="top"><img src="http://www.safetylock.esquare.info/images/valve/valve1.jpg" alt="" width="250" align="right" /></td> </tr> </tbody> </table>

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    returns the following, assuming all in a single cell

    GATE VALVE LOCKOUT Virtually indestructible valve covers. Once locked, they rotate freely around the hand wheel prevent the valve wheel from being turned. The strong polyurethane plastics make them resistant to cracking and abrasion. They are resistant to extreme weather and temperature conditions. Available in5 sizes ( Red colour )Other colours are available on request - minimum quantity applicable. 3 padlock holes are available in each gate valve lockout device. Different sizes cover most commonly used valve diameters. Withstands temperatures from - 20&deg;F to 200&deg;F Unique knockout center accommodates OS Y or &ldquo;rising stem&rdquo; valves. Suitable for hasps and padlocks. Dimensions Size Inside dia (A) Inside depth.(B) Outside dia. (C) Outside height (D) 25 - 63.5 mm 70 mm 32 mm 76 mm 38 mm 63.5 - 127 mm 130 mm 34 mm 140 mm 44 mm 127 - 165 mm 170 mm 41 mm 177 mm 50 mm 165 - 254 mm 257 mm 50 mm 267 mm 63 mm 254 - 355 mm 355 mm 63 mm 368 mm 74 mm MODEL PRODUCT DESCRIPTION ES -02 - GVL Fits on handle wheel dia from 25 to 63.5 mm ( 1" - 2½" inch) ES -04 - GVL Fits on handle wheel dia from 63.5 to 127 mm ( 2½" - 5" inch) ES -06 - GVL Fits on handle wheel dia from 127 to 165 mm ( 5" - 6½" inch) ES -08 - GVL Fits on handle wheel dia from 165 to 254 mm ( 6½" - 10" inch) ES -10 - GVL Fits on handle wheel dia from 254 to 355 mm ( 10" - 13" inch)
    Perhaps you should post a workbook example

  15. #15
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Andy - prev version of code works fine, but the newer gives error of #VALUE!. (stangely )

    I'll just do a search & replace to remove unwanted Text from final output.

    Thanks again.

  16. #16
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Question, why are you going about it so difficult?
    Wouldn't this just do the trick - assuming you put the source text into A1.

    Please Login or Register  to view this content.
    Gives output split per line in range A2 downward.
    Set reference to Microsoft HTML Object Library

    Works fine on all your supplied examples.
    Last edited by JasperD; 08-04-2015 at 08:17 AM.
    Please click the * below if this helps

  17. #17
    Registered User
    Join Date
    06-09-2015
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    52

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Quote Originally Posted by JasperD View Post
    Question, why are you going about it so difficult?
    Wouldn't this just do the trick - assuming you put the source text into A1.

    Please Login or Register  to view this content.
    Gives output split per line in range A2 downward.
    Set reference to Microsoft HTML Object Library

    Works fine on all your supplied examples.
    Not sure what you mean by "reference to Microsoft HTML Object Library" .

    Can you kindly elaborate on how use this code ? Where do i place it ? Under Modules (Alt + F11) ?

  18. #18
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: VBA Code to extract Text btwn ">TEXT<" ?

    Yes, under modules.
    Then in the top bar, go to Tools, References and select Microsoft HTML Object Library

    Then run the code, should work fine.

+ 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: 1
    Last Post: 08-15-2014, 06:00 AM
  2. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  3. Replies: 2
    Last Post: 04-20-2014, 11:18 AM
  4. [SOLVED] EXTRACT TEXT "SHM" or "SHGB"
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-29-2014, 07:57 AM
  5. Trying to extract "Text" inbetween ":" and ","
    By Paulzr27 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-06-2013, 05:48 AM
  6. Replies: 1
    Last Post: 10-22-2012, 09:38 AM
  7. Read select "text" from "Text File" using VBA code
    By naven_sg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2012, 04:01 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