+ Reply to Thread
Results 1 to 19 of 19

VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

  1. #1
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Hello All,


    Please see my attached workbook.

    I'm trying to make the Cells in column B match the colour of the cells in column C - they have a conditional formatting applied where they go darker red when they contain large numbers.

    Any ideas please?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,593

    Re: Conditional Formatting Colour Scales based on other Cells

    Unless the cells in column B match those in column C, you can't make the colour scale work on them.

    This is a limitation of the way that colour scales work.

    You may be able to do it with VBA - is that an option for you? Is it REALLY necessary for column B to have the shading? The more CF you have, the slower your workbook will become.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: Conditional Formatting Colour Scales based on other Cells

    Hello there,
    Yes VBA is an option, but I wouldn't know how to write the code for it.
    And Yes it is REALLY necessary to have column be shaded.

    thank you

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,593

    Re: Conditional Formatting Colour Scales based on other Cells

    OK - I will move you to the VBA section and hopefully one of the coders will help you out.

  5. #5
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    This is what I've come up with... It doesn't work - any suggestions please?


    Please Login or Register  to view this content.
    Last edited by AliGW; 07-19-2019 at 05:55 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,593

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. I will add them for you this time.)

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,593

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    My understanding is that VBA cannot detect colour applied via conditional formatting. What you will need to work with is the VALUE of the cell containing the CF shading.

  8. #8
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Apologies I tried to find the button to do it, but I'm afraid your forum doesn't make it particularly clear. I will do that in future

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,593

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    It's not my forum.

    Did you understand my comment about CF colouring?

  10. #10
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Use this UDF to get the color reference and then just set the next column to same

    Please Login or Register  to view this content.
    use as " = getcolor(the cell you select)"


    EDIT: Just tried tried it - doesn't recognise shading
    Last edited by nigelog; 07-19-2019 at 06:20 AM.

  11. #11
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    this is vba version - see can you set an offset to the values scales

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Hi Nigelog - thanks so much for your help - but I'm afraid it doesn't seem to be working like this.

  13. #13
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Finally found a way to do this

    Please Login or Register  to view this content.
    found code from Paul Kelly
    Please Login or Register  to view this content.
    Last edited by nigelog; 07-23-2019 at 03:58 AM.

  14. #14
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Amazing!!!! Thank you so much!!

  15. #15
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Glad to help - one of those projects that just caught my eye

  16. #16
    Registered User
    Join Date
    06-15-2019
    Location
    London
    MS-Off Ver
    2013
    Posts
    16

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    I've just tried to apply the updated version and I'm getting an "invalid procedure call or argument" popup box, any ideas please?

    Please Login or Register  to view this content.

  17. #17
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Hi I copied and pasted your code there into a new workbook module and it worked perfectly here on column c information

  18. #18
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Change to
    Please Login or Register  to view this content.
    see if that does it

  19. #19
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA: Mimic Conditional Formatting Colour Scales in Adjacent Column

    Hi Rowermax
    you would need to work out a way, with your data values and number of entries in the column, to keep the values between the parameters of RGB colours. The code fall over withing the second UDF I suspect due to not assessing the scale correctly.

    Without the data you have .. or indeed if it is constantly changing in size and value variation we may have hit a wall unfortunately.

    If you open a new thread with the data and workbook that did work, along with a copy of the data which is not working, someone else here might have an insight on the problem

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 33
    Last Post: 01-19-2018, 03:53 PM
  2. Conditional Formating, colour scales
    By Martinb86 in forum Excel General
    Replies: 1
    Last Post: 02-15-2017, 03:54 AM
  3. Replies: 5
    Last Post: 11-14-2015, 10:20 AM
  4. [SOLVED] Using/finding the colours from Conditional Formatting Colour Scales
    By I-Like-Excel in forum Excel General
    Replies: 2
    Last Post: 09-23-2015, 10:02 PM
  5. Conditional Formatting - Colour Scales
    By gruf1968 in forum Excel General
    Replies: 17
    Last Post: 10-15-2010, 07:28 AM
  6. colour scales conditional formatting
    By mattianperry in forum Excel General
    Replies: 1
    Last Post: 10-15-2010, 06:43 AM
  7. Conditional formatting and differing time scales
    By Ducatisto in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-27-2008, 05:14 AM

Tags for this Thread

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