+ Reply to Thread
Results 1 to 9 of 9

VBA script; Trim away everything except x,y,z etc?

  1. #1
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    VBA script; Trim away everything except x,y,z etc?

    Is it possible to specify to trim/remove all text except certain words from "sDD = appIE.document.getElementsByTagName("dd")(22).innerText".
    For example: Trim away everything except x, y and z, which leaves me with just x, y and z given that they are in the text that is getting trimmed.

    My current working script;

    Please Login or Register  to view this content.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA script; Trim away everything except x,y,z etc?

    Can you give us an example since x, y and z don't exist in the string you provided. Are x, y and z single characters or substrings. How many can there be?
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA script; Trim away everything except x,y,z etc?

    Never mind. I think I now understand what you need. Here is a function that will take out specified strings. Give it a string, and the substrings you want to remove separated by commas. For example TrimAway ("Foobar","oo") yields "Fbar" and Trimaway ("Foobar","oo,a") yields "Fbr". The function is case sensitive.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    Re: VBA script; Trim away everything except x,y,z etc?

    Quote Originally Posted by dflak View Post
    Can you give us an example since x, y and z don't exist in the string you provided. Are x, y and z single characters or substrings. How many can there be?

    Some examples of what x, y, z.. etc can be
    Emberiza citrinella
    Lagopus muta
    Lagopus lagopus
    Melanitta nigra
    Falco rusticolus
    Carduelis flavirostris
    Accipiter gentilis

    There are 577 species in total.

    Im trying to stripp away all the other text so that I can see which species are present at various sites. I have already a script that does give me the relevant paragraph in a cell, so If I could specify
    either by linking the script to the excel spreadsheet where I have all the species or write them all into the script to make the script just look for them and if they are there, copy/past them into the spreadsheet, is that doable?

    Sorry If my question was a bit ambigious


    Thanks for aiding me

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA script; Trim away everything except x,y,z etc?

    Oops! I got it backwards. How about an alternative? You provide the list of species, and the application will tell you if the species appears in the paragraph? or better still, which species appear in the paragraph.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA script; Trim away everything except x,y,z etc?

    OK, Let's try this. On the species list tab, there is a list of species in an Excel Table. You can copy and paste your list into this table. One of the nice things about Excel tables is they know how many rows they have, so if you add names or delete them the code will keep up.

    For purposes of demonstration, I embedded some of the species names in the sample paragraphs. You can pass the paragraphs in your code.

    It would probably be best if you copy this code into your existing workbook. It depends on having a table named Table_Species with the column header Species. Here is an introduction to tables in case you are not familiar with them: http://www.utteraccess.com/wiki/inde...ables_in_Excel.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    Re: VBA script; Trim away everything except x,y,z etc?

    hmm, this might work. I have never seen a xlsb file before :P
    Did you write any code, if so how do I get to it?

    Thanks

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA script; Trim away everything except x,y,z etc?

    XLSB files are XLSX or XLSM files with a lot of the XLM stuff removed from "under the hood." Generally speaking, they are a lot smaller in size.

    Yes, I did write code and you can get to it by pressing ALT-F11. This brings up the VB editor. The following is the code you will see, I added a lot of comments to this post to explain what the code is doing. The only line you would have to change is For Each cl In Range("Table_Species[Species]") if for some reason you change the table name.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    Re: VBA script; Trim away everything except x,y,z etc?

    It works, thank man! :D
    Last edited by mss90; 05-12-2016 at 04:00 AM.

+ 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 TRIM is won't TRIM active worksheet
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-06-2014, 09:55 AM
  2. calling the vb script from the shell script(unix platform)
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 06:21 AM
  3. Integrating Mainframe emulator script with excel's vba script
    By Himanshu Mishra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 10:30 AM
  4. Create VBA script to short, dedicated button in excel for script?
    By realized in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2009, 11:54 PM
  5. Script that edits the text printed on the button that runs the script
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2008, 02:41 PM
  6. Trying to trim a trailing space char and the Trim function isn't working
    By Psychochook in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2007, 11:28 PM
  7. [SOLVED] VBA Trim and Application.worksheetfunction.Trim
    By Hari Prasadh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2005, 11:06 AM

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