Formatting Range of Cells of within gap of 3 value / Factor for 3 levels

  • Hello Seniors,


    I want a macro that will


    1) allow / Prompt user to select the Range of cells across Rows & Columns, and do the following


    2) From Range of Cells at three levels (max 3, or less than three is also okay, and if there is no such cases, nothing to highlight or no message to be given).

    In Sample Workbook, attached here, the Range to be evaluated is A6:H9. However, on user selection, it could vary in terms of Row, and Columns, but dont expect it to
    be more than 10 x 10 matrix.


    3) Now upto 3 levels, Each of cell value should be compared within range as mentioned in 2) above, within value / factor of 3 points, and if matched, should be highlighted through color.


    4) In the given workbook, just for illustration purpose, i have done this manually, and applied different color to make it clear, what i seek.


    5) Just for illustration purpose, i have highlighted upto 4 levels (4 colors, where numbers are within 3 factor/point from each other), but it is okay, if macro or formula could highlight upto max 3 levels only.


    Thanks

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    Interesting...


    why isnt C8 coloured Green?


    Does it have to be conditional formatting? Or just normal formatting?


    I guess you DONT need to summary of the sets, just colour in the sets?


    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels



    Thanks for looking in.



    You are right,
    C8 Yes, that is manual /inadvertent mistake, and it should have been colored, Green. Sorry for this inadvertent mistake.



    Normal Formatting or Conditional formatting either will do, as after running the macro, it should highlight such set of data. (If possible allow to see how conditional formula would have been set for such work.)



    Yes, No summary is needed, since possible block would have range that can fit on the screen, and 3 or lesser colored set could be visually seen.

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    Here is an inefficient brute force method which will capture up to 6 sets / levels with a gap of 3. On a small matrix it should be fine, but I wouldnt run this on 1000x1000 matrix - you might have to go for a cup of tea in that case.



    Seems to work... Conditional formatting is NOT possible AFAIK.


    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    Ger Plante, simply superb, Sir, exactly what i wanted.


    Kindly have a look at A9 (188) and B9(192) this has gap/factor of 4 points, so either one of A9 (188) or B9(192 ) should have been ignored. Nonetheless, this could be due to comparison of it with B8 (189) and hence both got selected.


    See, if doable, else, your given code is perfectly alright. Thanks, and Awesome.


    Suppose, if i want to tweak the code with only 2 scenario / level only and with gap /factor of only 2 instead of 3 currently, which line i should change.


    For Factor of 3, i guess, you set the line at


    Code
    Const GAP = 3


    When i changed this to 2,
    it ignored Grey color shading in cell D2 (337) and H2(340) but


    continued Green color shading in cell B2(347) and G3(345) ?


    If i reduced the number of color to any level less than yours , you have set 5 color, what difference it will make?

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    Quote


    Kindly have a look at A9 (188) and B9(192) this has gap/factor of 4 points, so either one of A9 (188) or B9(192 ) should have been ignored. Nonetheless, this could be due to comparison of it with B8 (189) and hence both got selected.


    Your guess is correct... its because of the comparison with B8 (189) that brought it within the 3 point gap. In my head that would be right :) The code sort of creates a linked list (or chain) of cells that are within three of each other. For example - really simple example - with just three cells on the row... values are 3, 6 and 9 - the gap between 3 and 6 is just 3 so that will be highlighted, but also in the same way the gap between 6 and 9 is also 3, so that will be highlighted too in the same chained list of cells. I'm not sure what logic you would consistently employ to say that 3 and 6 are linked by a gap of three, but seperately 6 and 9 are also linked by a gap of three. Since 6 is common to both, you cant have one cell with two colours at the same time, so they end up getting the same colours as they are part of that link / chain. But I understand that 3 to 9 is a gap of 6 and therefore breaks the Gap rule with those figures. But I'm stuck. Basically in my example 3 and 6 would be one colour, and 6 and 9 would be another colour... but six cant be both colours :)



    Quote

    if i want to tweak the code ... with gap /factor of only 2 instead of 3 currently
    When i changed this to 2,


    Correct - to change the GAP, update the CONST GAP numbers from 3 to 2 (or increase if you wish). Well spotted


    Quote

    if i want to tweak the code with only 2 scenario / level


    For example for just two scenarios, change rsets(5) to rsets(1) ... why one? Because the index here starts at 0, so rSets(0) and rSets(1) will give two scenarios. It will beasically ignore all other groups/chains and find (from the top left cell in the selection) only two scenarios and ignore other possible scenarios.
    rSets(5) is actually giving you 6 scenarios. If you want more than 6 scenarios, you will need to update the CONST Colours statement as each number between the comma's is a colour, and I have only defined 6 colours ;) So you might get an error, or a black fill for anything more than 6 scenarios, until you add more to that CONST Colours line at the top.


    Regards
    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    I dont have words to say, but Sir, you have awesome clarity in understanding the user requirement, and make your code with enough flexibility to customize it. Hats Off.


    THANKS YOU VERY MUCH.

  • Re: Formatting Range of Cells of within gap of 3 value / Factor for 3 levels


    :cool: :D

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!