+ Reply to Thread
Results 1 to 20 of 20

Find last instance of a word and insert blank row

  1. #1
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71

    Find last instance of a word and insert blank row

    Hi everyone (again!)

    I hope I'm not posting too often on here? I have another thing I'd like to do, and would appreciate the help/guidance.

    In my spreadsheet of data, I would like to be able to add vb code to my developing macro that searches within 1 column for the last instance of a particular word, then inserts a blank row under that word. All the data is sorted, so the words will be used multiple times, but I need the row to go under the last instance of each word in the column.

    Hope you can help!
    Last edited by HelenW; 12-11-2008 at 01:21 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Is this in your last workbook, if so which sheet are you referring to?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    See the attachemet if this is of any help to you
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    Sorry Roy - didn't want to assume you'd still be there to help! Yes, it's my last workbook but have attached the one I am working with as it is less clogged up with macros.

    I want to seach down column F, find the last instances of Eastern, Southern, and Northern, and insert a blank row underneath the last instance of each to separate each section. I would want to format this row by filling the row up to column N with another colour.

    There will be a differing amount of data each time the spreadsheet is used, and it is possible that one of the above instances might not appear - can that be incorporated?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    Thanks Shijesh - can that be automated so that you don't have to type in the words to find? It will always be the same 3 words.

    ETA that I think I figured out to do it! Thanks!
    Last edited by HelenW; 12-11-2008 at 12:37 PM.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Which column is it? Do you just want to add blank rows whenever there is a change in the names?

  7. #7
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Hope this will be near to what you want if not the exact

    see attachemnt
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Quote Originally Posted by Shijesh Kumar View Post
    Hope this will be near to what you want if not the exact

    see attachemnt

    Ignore the above Post...
    I didn't see your above post....

  9. #9
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    OK, I had this working, then it stopped and says that the variable is not defined (c). This is what I had working, and it inserted a row under the last instance of Northern, of Southern and of Eastern (they are sorted already, we just won't know how many there will be each time).

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    Yes, a blank row whenever there is a change in name in column F.

  11. #11
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Hi

    The above code is perfect...
    Its running without any error ....

  12. #12
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    code to automate it

    In VBA editor double click on Sheet1(Data) and put the code there...
    Don't put this code in module .... put it in sheet where u want to run this code


    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    Just ran it again, and you're right - it works. Onto the next bit now! Thanks for your help (again!).

  14. #14
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    What an idiot - just realised that I need to insert a row ABOVE the FIRST instance, not below the last! How do I change to code to do that please??

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This will add a row at each change in value of Column F
    Please Login or Register  to view this content.

  16. #16
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Quote Originally Posted by HelenW View Post
    What an idiot - just realised that I need to insert a row ABOVE the FIRST instance, not below the last! How do I change to code to do that please??

    modified code

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    Thanks Roy - that works, except it doesn't differentiate between Southern and Strategic, and leaves them together as one big block - any ideas?

  18. #18
    Registered User
    Join Date
    09-18-2008
    Location
    Devon
    MS-Off Ver
    2002
    Posts
    71
    I'm off now, but will definitely be returning to this next week! Thanks for your help so far.

  19. #19
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It works fine for me.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    12-09-2010
    Location
    Listowel, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Find last instance of a word and insert blank row

    Please Login or Register  to view this content.


    I used this instead of column F I changed it to a range.
    But it just cycles through and doesn't insert and doesnt give error.
    Can someone help me out?
    Last edited by Leith Ross; 12-10-2010 at 01:09 AM. Reason: Added Code Tags

+ 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