+ Reply to Thread
Results 1 to 11 of 11

VBA for adding borders to a range based on condition?

  1. #1
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    VBA for adding borders to a range based on condition?

    I have a spread sheet I use to track tools. One tool may be checked out / returned several times a week. When I do custom sorting I end up with the Tools listed neatly by date and number. EX:

    A1 b1
    7/11/09 Tool1
    7/12/09 Tool 1


    7/11/09 Tool3
    7/12/09 Tool3 etc.

    I have a macro that inserts a blank row between dissimilar tool numbers. What I'd like to add is another macro that adds a box border around the range of cells for each particular tool. So that it looks something like this.

    ___________________________________________________________

    7/11/09 Tool1
    7/12/09 Tool 1
    ___________________________________________________________

    ___________________________________________________________
    7/11/09 Tool3
    7/12/09 Tool3 etc.
    ___________________________________________________________

    The problem I'm having is that each time I add a new row to a particular tool number - I have to go in and manually adjust the border. I don't know enough to account for an unspecified range of cells - I never know how many times a tool will be used - or consequently how many cells the box border wit will need to go around.

    Any help would be appreciated.
    Last edited by antonymiller; 07-14-2009 at 03:46 PM. Reason: solved

  2. #2
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: VBA for adding borders to a range based on condition?

    Hi,

    Please Login or Register  to view this content.
    Adjust the range

    HTH
    Kris

  3. #3
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: VBA for adding borders to a range based on condition?

    Hi Krish -

    Thanks a lot, this is way simpler than the approach i was trying to take. I failed to represent in my original post that there is a empty row between each data entry.

    ___________________________________________________________

    7/11/09 Tool1
    EMPTY ROW
    7/12/09 Tool 1
    ___________________________________________________________

    ___________________________________________________________
    7/11/09 Tool3
    EMPTY ROW
    7/12/09 Tool3 etc.
    ___________________________________________________________


    How can account for these empty rows between tool entries and still manage to get the borders around the range of cells for that particular tool?

    Thanks

  4. #4
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: VBA for adding borders to a range based on condition?

    Still not sure about your layout. Post an attachment here.

    Kris

  5. #5
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: VBA for adding borders to a range based on condition?

    Hi Kris,

    Here is the attachment- it pretty much outlines what I'm shooting for.
    Mainly just need to figure out how to get the borders to appear around the perimeter of the first and last row a particular tool number appears in.... the blank rows in between shouldn't have a top or bottom border.

    Thanks again.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: VBA for adding borders to a range based on condition?

    Hi,

    There may be better solution...

    Please Login or Register  to view this content.
    HTH

  7. #7
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Thumbs up Re: VBA for adding borders to a range based on condition?

    Kris,

    It's perfect thanks - it would have been a while before i got this far on my own.... thanks a million!

  8. #8
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question Re: VBA for adding borders to a range based on condition?

    I've been trying my hardest to apply the macro help I've received to other worksheets I use. With little luck.

    Specifically, I have an inventory sheet that isn't vary complicated. I do a custom sort on it and everything condenses rather nicely but it is undreadable. So I've been asked to add empty rows between each line. The macro I am trying to use doesn't effect the entire row, only the first cell and it moves the headers as well. My limited knowledge is a problem in fixing that.

    My second macro is meant to place a single box border around all the rows that contain the same ID number - all unique ID's are boxed in together for easier reading. Again, it just isn't working out that way. Mainly because I can't figure out how to alter to box things in correctly.

    this is a macro that I'd really like to learn from as this is the kind of thing I get asked to do all the time, and I hate having to do it manually - takes forever.

    I know both of these macros work - I got them here from very helpful people and have used them already in other forms successfully. I just don't understand VBA well enough yet to get them to work in a new worksheet with different layouts.


    I have attached my workbook - any assistance would be appreciated.

    Thanks
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: VBA for adding borders to a range based on condition?

    Hi,

    To insert the rows use first macro and the nrun the second macro to create the border.

    Please Login or Register  to view this content.
    HTH

  10. #10
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question Re: VBA for adding borders to a range based on condition?

    Hi Kris,

    I get a compiler error stating that the Sub or function is not defined for the second macro.

  11. #11
    Forum Contributor
    Join Date
    02-19-2005
    Location
    Gurgaon,India
    MS-Off Ver
    2007,2010,2013
    Posts
    180

    Re: VBA for adding borders to a range based on condition?

    I think you have the sub CreateBorder on another module. If not include the sub CreateBorder in this module too.

    HTH

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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