+ Reply to Thread
Results 1 to 9 of 9

VBA to return values based on cell formats

  1. #1
    Registered User
    Join Date
    06-10-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    5

    VBA to return values based on cell formats

    Hi, thanks for looking in.

    I have a data table for which I need to return start and end date values based on the format of the cells in the table.
    The table is shown in the image attached. Essentially it is a simple workflow table with peoples names on the y-axis and dates of when work commences and ends on the x-axis. The data array cells are then color coded to reflect start and end times for each resource. I need the macro to read across the table find the first blue(color index 33) cell then lookup up the date in the header row, this is the start date, then populate this in the start date cell. Then move across the row until the last interior shaded blue cell and lookup the date on the header row which is then the end date for that resource which should populate the "end date" cell. The code should then loop through all rows before ending.

    XL help.png

    Somebody has already very kindly provided me with some code to solve this problem. The code is:
    Please Login or Register  to view this content.
    I copied and pasted the code into the workbook, but when I ran the macro nothing appears to happen. I tried stepping into the code but it doesn't reveal any errors. I'm sure this is something obvious which I'm not doing right. I have an intermediate knowledge of VBA and I have tried to understand the code provided and I can follow most of it, but I can't see where it defines variables "A", "B" and "C" nor can I see where it enters the start and end date values to the results cells ?

    Please can you help fix the code. As I say it is no doubt down to my lack of knowledge rather than a problem with the code itself.
    Many thanks
    H
    Last edited by xl121; 06-10-2012 at 08:51 AM. Reason: Please use code tags in future.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA to return values based on cell formats

    How are your blue cells colored; manually by the user, or with Conditional Formatting? It matters. Your code should work if the cells are manually colored and not with Conditional Formatting.

    Also, double check that the .Interior.ColorIndex of your colored cells is the same as in the code (33). It "looks" good to me though.

  3. #3
    Registered User
    Join Date
    06-10-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA to return values based on cell formats

    Hi AlphaFrog,
    I've checked the cells color indes which is 33. The cells are maually fiilled blue(33).
    But nothing happens when I run the macro? I opened the workbook with my table, pressed Alt F11 then copied the code straight into the VBA window, saved the code.
    Ran the macro but nothing happens? I've recreated another example with simple data and again nothing happens when I run the macro?
    Thanks AlphaFrog for your help.

    Not sure what I'm doing wrong?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA to return values based on cell formats

    I tested your code and it worked for me.

    Make sure column A has values. It loops through each row where column A has a value in it.

    Otherwise, attach your workbook file.

  5. #5
    Registered User
    Join Date
    06-10-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA to return values based on cell formats

    Hi AlphaFrog,

    Still can't get this macro to run, not sure what I'm doing wrong.
    I've attached the work book with just one page and the macro on it.

    Thanks again for your help.
    Kind regards
    H
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA to return values based on cell formats

    You have the macro located in a worksheet code module. Move the macro to Module1.

    Excel VBA -- Adding Code to a Workbook

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA to return values based on cell formats

    hi xl121, change this line:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-10-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: VBA to return values based on cell formats

    Thanks AlphaFrog and watersev for all your help.

    Using the "Application.FindFormat.Interior.Color = 15773696" line the code ran perfectly.
    I wonder why it didn't work for me using 33 as it did for AlphaFrog?

    If "15773696" is some kind of boolean translation of color 33 then how do I get a list of colors in the "long format", is there a piece of code that will tell me the "long format" of the interior color?
    Final question, how would the code differ if it were based on conditional formating of the cell rather than user defined color formatting?


    Thanks again both, I really appreciate your help.
    Kind regards H.
    Last edited by xl121; 06-11-2012 at 03:18 PM.

  9. #9
    Registered User
    Join Date
    12-31-2012
    Location
    Iraq
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA to return values based on cell formats

    Using RGB formatting is better

    Application.FindFormat.Interior.Color = RGB(255, 255, 0) ' for yellow

    Regards
    Mudhafar.M

+ 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