+ Reply to Thread
Results 1 to 11 of 11

Borders Error

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Borders Error

    Im having a problem with a some VBA for borders in that I am getting an error. The error has only occured since putting in the code for the borders. The error is:

    Run-time error '1004':

    Application-defined or object-defined error

    My code is:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Borders Error

    Please post a sample workbook.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Borders Error

    File Attached. Please be gentle with me!
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Borders Error

    Hi try this
    Please Login or Register  to view this content.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Borders Error

    Tom has provided a solution.

    The reason for the fail is that you cannot select a cell or range when you have not selected the worksheet. Using With ... End With overcomes this.

    You could, if you wish, reduce the amount of code using:

    Please Login or Register  to view this content.

    As, most of the time, you'll be setting the same style, colour, tint and weight, this is a better and simpler option. If you want to apply a different parameter to one of the borders, you could do that separately after setting all the borders.

    Regards, TMS

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Borders Error

    I note that Tom's solution still has "Selection." in it but the "Select" has, rightly, been removed.

    You need to qualify all of the properties or use With ... End With as described in the previous post.


    Regards, TMS

  7. #7
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Borders Error

    OK, thank you for all the help guys. I ahve applied the code and it works really well. I also have some code that clears the cells so ned to clear any line styles as well. My code is :

    Please Login or Register  to view this content.
    Last edited by dadrew; 09-06-2012 at 11:27 AM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Borders Error

    New question ... should be a new thread.

    And you need to add code tags or suffer the wrath of the moderators.

    Regards

  9. #9
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    73

    Re: Borders Error

    Quote Originally Posted by TMShucks View Post
    New question ... should be a new thread.

    And you need to add code tags or suffer the wrath of the moderators.

    Regards
    New thread started, I did put it in code tags but made a typo, hence the reason it wasn't in them OOOPS!

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Borders Error

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,456

    Re: Borders Error

    You're welcome. Thanks for the rep. And thanks for sorting the tags, easy thing to get wrong.

    Regards, TMS

+ 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