+ Reply to Thread
Results 1 to 7 of 7

borders between 2 specific words

  1. #1
    Registered User
    Join Date
    07-02-2009
    Location
    montreal
    MS-Off Ver
    Excel 2003
    Posts
    13

    borders between 2 specific words

    Hi all,

    I have this bit of code that I need help with:

    Please Login or Register  to view this content.
    I am trying to is create borders around all cells in the range by looking for 2 specific words to begin and end the borders. Let's say word1 & word2. The border should begin after (under) word1 and end before (above) word2. It will also happen that there will be several occurrences of word1 & word 2 but it should only create the borders between word1 & word 2 for every occurrence of those words.

    Now this code seems to works but only for 1 occurrence of word1 & word2 (from the bottom up) and all the others are ignored

    Can someone help please ?

    Pedy
    Last edited by pedy; 07-08-2009 at 11:06 AM.

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: borders between 2 specific words

    Pedy,

    Your .Find statements are using xlPrevious, which means that they search backwards through the range. This is the reason it is always the 'last' pair that get affected.
    Also there is no looping in the macro above, (other than to colour & border the rows of a single pair), which is why it does not operate on any other pairs. Try the code below, I have tried to explain it in comments, but please ask if there is anything you are unsure about:

    Please Login or Register  to view this content.
    Incidently why do you have the macro in the selection change macro? This means it runs every time you move the cursor on the sheet, clearing all the formatting and redoing it...
    Last edited by Phil_V; 07-02-2009 at 09:32 AM. Reason: "Application.ScreenUpdating" added
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Registered User
    Join Date
    07-02-2009
    Location
    montreal
    MS-Off Ver
    Excel 2003
    Posts
    13

    Thumbs up Re: borders between 2 specific words

    That's great, thanks Phil!

    I was using the selection change to make testing quicker.

    Thanks agin :D

  4. #4
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: borders between 2 specific words

    No worries. If this solves the case please mark the thread as Solved;

    Edit your first post, click [Go Advanced].
    In the prefix dropdown box select 'Solved'.

  5. #5
    Registered User
    Join Date
    07-02-2009
    Location
    montreal
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: borders between 2 specific words

    Hi again,

    Would it be possible to insert another part to this code?

    Before the borders routine, I would like to look for the highest value (number) in a whole column in all of the occurrences of the 'word1' & 'word2'. Once it returns the highest value it will use that value and enter a combination of the words “In” in the next cell (the cell next to ‘word1’) and “Out” in the cell next to the previous cell (that now has ‘In’). The highest value is used to enter that combination (“In” & “Out”) in the next cells.

    Ex.: if we look in column B and the highest value is 5, and the ‘word1’ is in cell A3 then it will enter “In” in cell B3 & “Out” in cell C3. This is done for a total of 5 times (ten cells total).

    Now the example will change a bit because before the loop of “In” & “Out”, the word “Out” must be entered once before the loop.

    So the changed Ex would be:

    if we look in column B and the highest value is 5, and the ‘word1’ is in cell A3 then it will begin by entering “Out” once in cell B3 and then loop “In” in cell C3 & “Out” in cell D3. This is done for a total of 5 times (eleven in total (ten cells for the loop + the 1st “Out”)).

    I must also mention the column that we’re looking in to find the heist value contains stuff like “4 / 8 – 10” or “5 / 8 – 10 g”. And also the tables (occurrences of ‘word1’ & ‘word2’) are separated by empty rows.

    I hope I have described it ok.

    Pedy

  6. #6
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: borders between 2 specific words

    Pedy, Are you able to upload an example workbook as this would make it much clearer.
    Perhaps one sheet of example input data, and one sheet with an example of what you want as an output?

  7. #7
    Registered User
    Join Date
    07-02-2009
    Location
    montreal
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: borders between 2 specific words

    Before:
    Please Login or Register  to view this content.
    After:
    Please Login or Register  to view this content.
    In this example 7 is the highest value (1st number in the cell) found in the column so the paired 'In' 'Out' loop will be inserted 7 times (7 'In' and 7 'Out').

    Pedy
    Last edited by pedy; 07-08-2009 at 01:05 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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