CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    1

    Copying cells to new workbook based on cell background....

    Hello All,

    I have been working away on this problem for several hours and can't seem to get my code to work. I thought someone here might be able to solve it pretty quickly.

    I have a workbook (column A:M) which uses conditional formatting for row M. The conditional formatting is different for all of the rows (there are currently over 100, and more might be added). I need to get a macro that will copy all cell values in the row from A:L to a new workbook when the value of M is colored red or yellow.

    I was also wondering if it is possible to automatically name the new workbook based on the date.

    Thanks for all your help!

    Stu

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Copying cells to new workbook based on cell background....

    Just record a macro, then open it in the Macro Editor. You will see the VBA code, which is pretty close to VB6, so you can translate it (or post here for help)

    We need to see CODE, though
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Copying cells to new workbook based on cell background....

    I don't think it's possible to read out a format property of a cell determined by conditional formatting. You'll probably have to track the condition the format is based on yourself, and as apparently that condition can vary from cell to cell you'll likely have no other choice than reading it out of the FormatCondition object that is conatined in the FormatConditions collection that is a property of a Range object (IOW the cell). And as the condition is not (necessarily) stored as an Excel formula, it can't be easily evaluated programmatically (and I don't even recall exactly how this is done at the moment but I could try to research it if it helps).

    Sorry that I didn't have more encouraging news.

    But anyway... Welcome to CodeGuru!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Copying cells to new workbook based on cell background....

    You can read the properties of a cell, formatted or not. Sounds like it's all Excel, anyways!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured