Consulting

Results 1 to 16 of 16

Thread: Identify cells with color fill and borders

  1. #1
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location

    Identify cells with color fill and borders

    Hey guys,

    I'm trying to loop through each worksheet in a workbook, copying the color indexes and borders from any cells that have them to another workbook with an indetically named worksheet. I have comitted the ultimate sin in trying to do this with a loop, but unfortunately the workbook has 261 worksheets, and some are over 10,000 rows each. (Please no lectures on workbook design, I'm doing this for someone else.)

    The thing is that I ONLY want the cells.interior.colorindex and the cell borders, and I don't want anything else.

    Is there a way to identify/copy these things quickly?

    Thanks,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Hi Ken


    What Color is used in font, interior and borders

    Dont know if this will get you going or not. Found with a search:
    http://www.pvv.ntnu.no/~nsaa/excel.html




    Might have to modify it to suit your needs.
    Peace of mind is found in some of the strangest places.

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    How many times is this supposed to be done Ken? If it's just once, a loop doesn't sound out of the picture here. It may be a lot of sheets, but I'm sure you can streamline a loop to run efficiently.

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    LOL,

    I've streamlined it the best I can, but it still needs to look at every cell to see if there is a colorindex and/or borders, then copy them to the new sheet.

    With 261 sheets, lots of columns on each, and tons of rows... It's been running since last night at 11:00PM, (Pacific). As of Noon (13 hours), it was almost half way done.

    I'm waiting for Dave to come call me a sinner, but I have no idea how to thin down those ranges any more? Specialcells has something for conditionals, but nothing for just plain formatted cells.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I wonder if it wouldn't be faster to use the GET.CELL method. Paddy's post at MrE does a fine explanation of this.. then you could peruse only those cells in a seperate column of formulas which meet your specifications. Could speed it up plenty if you set it up right (I would think - without seeing the data of course).

    Thread referred to is here: http://www.mrexcel.com/board2/viewtopic.php?t=21312

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hey Zack,

    It's interesting, but wouldn't you still have to do the same? Loop through each cell, querying if it matched a criteria and then act? That's essentially what I've doing now.... did I miss something?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Yes, but you could trim it down drastically. Let's say you built a couple of extra columns on each sheet (done easily enough by selecting all sheets and entering your formula at once, confirmed with Ctrl + Enter). I'll say for now that you are using a column to test the entire row for any conditions met. Let's also say that you used an IF function to represent all those with matching criteria to leave a 1 and those that do not to leave a 0. You could then autofilter for 1 and use special cells to loop through just the rows which have matching criteria somewhere in them.

    This of course is really dependent upon data structure and what you're looping through. It may - or very well may not - save you time. But the picture in my mind, well, isn't always right, but may save you time.

  8. #8
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Ahhh! Okay, I think I see where you're going with this. Yes, don't know if it would work, but is certainly worth a look. I think I'm going to let it run the rest of the 7-10 hours it needs to complete (I wouldn't want to have to do it again), but it might be helpful to try it for future.

    Thanks!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    If you know where it's at in the process, you can always adjust the loop(s) to start there .. 7 to 10 hours is a long time. I'm thinking you could beat that.

  10. #10
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    LOL!

    I could, but I have so much invested in it at this point that I'm afraid to touch it!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  11. #11
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Since I can't say it well enough myself, I'll let somebody else say it ...


    Quote Originally Posted by Albert Einstein
    The most important thing is to not stop questioning.

    Quote Originally Posted by Albert Einstein
    Problems cannot be solved at the same level of awareness that created them.

  12. #12
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Ken,

    I understand that data and formulas aren't to be copied, and naturally I assume you don't want names, validation, conditional formats and comments copied either, but each cell has a format that includes borders and colour, so can the rest of these formats be copied (e.g. "General", "Number" etc)?

    If so, do a paste special (formats) to a temporary sheet (names, validation and comments won't be copied), delete all conditional formats with [vba]Cells.FormatConditions.Delete[/vba] on the temp sheet, then copy this altered temp sheet and paste special it (formats again) to where ever you want.

    ????
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  13. #13
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I looked at this and decided there were too many (possible) variables - a general solution would be interesting but for a one-off it's not worth the effort and I would just let the simple loop run the day or two it takes.

    The trouble with what you suggest, John, is that it will overwrite all existing formats on the target sheet.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  14. #14
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by TonyJollans
    I looked at this and decided there were too many (possible) variables - a general solution would be interesting but for a one-off it's not worth the effort and I would just let the simple loop run the day or two it takes.
    Yep. I worked on other stuff on my wife's PC and just let her go. At least we have two! All in all, it took 32 mind boggling hours to complete on a 3.06Ghz with 512MB RAM. Yikes!

    Quote Originally Posted by TonyJollans
    The trouble with what you suggest, John, is that it will overwrite all existing formats on the target sheet.
    Indeed. I needed to make sure that the rest of the formats weren't touched. Only colorindexes and borders.

    Zack, I may still try your suggestion, more for curiosity at this point than anything else.

    Thanks!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  15. #15
    I can't quite get it straight iin my mind, but I can't halp but wonder if it might get done quicker if you broke it down into multiple copy sessions. You know, maybe you're getting virtual storage thrashing or something. Can you say with any certainty that dividing it into, say, 5 runs instead of one will wind up with the same overall elapsed time of execution?? (Just thnking out loud.)

  16. #16
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I wouldn't think so, Sid. Not if running the same code. The only thing you'd be doing there is making it compile 5 times instead of one, and creating yourself more overhead. Unless the code efficiency was directly changed, I can't see any difference except negative.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •