+ Reply to Thread
Results 1 to 20 of 20

Put color to cells

  1. #1
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Put color to cells

    I have a table with changing lengths of the rows and columns. At the end of each row/column there is a cell with the sum. I want to put some color to it and make some additional formatting - have some borders around the main table and different colors for the empty and non-empty cells. I have the following code:
    Please Login or Register  to view this content.
    which gives me error 438 - Object doesn't support this property or method. I can't find any errors in the code and I guess there is a problem with the range.Could you help me?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    You don't need code to colour the cells - use Conditional Formatting - http://www.excel-it.com/excel_condit...formatting.htm

    I also find it much easier to have the totals above the data table. They are then easier to view and can be written to reflect the change in number of rows. SubTotal is also a good choice because you can filter & get a total of filtered lines
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Put color to cells

    Maybe a little faster this way:
    Please Login or Register  to view this content.
    Meanwhile, I'd probably use conditional formatting so this happened on its own in realtime.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    As this is part of a bigger project I want it all written with macroses. Conditional formating is not an object for me. As for the sums - I need them to be placed at the end of the rows/columns because this is one of the requirements.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    Try this, alter the colours to suit

    Please Login or Register  to view this content.
    Last edited by royUK; 06-02-2009 at 12:17 PM.

  6. #6
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    Yes, this puts color in the main table and bounderies on the whole range. How can I put bounderies on the table only and leave the blank cells without any?

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    Do you mean around the outer edge?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    I mean I want to have visible bounderies around the cells that contain any value an have no bounderies around the ones that are blank.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Put color to cells

    Quote Originally Posted by Manhamanha View Post
    Yes, this puts color in the main table and bounderies on the whole range. How can I put bounderies on the table only and leave the blank cells without any?
    I think that's what mine in post #3 already does for you. Give that a shot.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    just a slight amendment needed
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    This works great Just one more thing if you have time.. how can I put a different color in the last row and column - the ones with the sums.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    Is your range fixed because you hard code it?

  13. #13
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    No it is not. The rows and columns length vary depending on a number that is entered by user. After that they are filled with special numbers and the sums are calculated. The values I had as range to check in were just example.
    Last edited by Manhamanha; 06-02-2009 at 01:02 PM.

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    I would replace it with UsedRange or set the range with the code
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    It really looks better this way. What about the different color of the last row/column - is it possible?
    And do you have any idea why does this throw error 400 ?

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Put color to cells

    My last code did that
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    Well, it doesn't.. it throws 400 and colors all the 'non-empty' cells with one and the same color.

  18. #18
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    Ok, it's getting too complicated to explain, so here is the whole code:
    Please Login or Register  to view this content.
    I have changed the filling color in your method.
    I'm attaching a few pictures too. The first one with the error I get. The second one is how the table looks now and the last one is how I want it to look.
    I hope it's clear now - take a look if you have time..

    Thanks anyway a lot
    Attached Images Attached Images

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

    Re: Put color to cells

    Attach the workbook. The final code that I posted worked like that for me.

  20. #20
    Registered User
    Join Date
    06-02-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Put color to cells

    Hi, I managed to deal with it by deleting one of the lines from your code

    .SpecialCells(xlCellTypeConstants).Interior.ColorIndex = xlNone

    It seems that the problem is with those "SpecialCells". At least now it puts the color as I want it to be and gives no errors. As for the blank spaces I'll figure it out later. Thanks againg for the great help, I really appreciate your efforts

+ 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