• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Conditional formatting via VBA does not apply any formatting|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Conditional formatting via VBA does not apply any formatting|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosConditional formatting via VBA does…
sp_PrintTopic sp_TopicIcon
Conditional formatting via VBA does not apply any formatting
Avatar
Dave MacIntyre
Member
Members
Level 0
Forum Posts: 7
Member Since:
April 30, 2019
sp_UserOfflineSmall Offline
1
February 10, 2020 - 8:14 pm
sp_Permalink sp_Print

Hi all

On the attached spreadsheet I have a macro setup that, depending on which colour cell is selected in row 2, should then use conditional formatting to fill all cells that are not of the selected colour in white and make the font white (i.e. to blank out all cells that are not that colour). All works fine in that when you select the relevant colour cell in row 2, the conditional formatting is added when you click the macro button (in the top left corner), but no formatting is applied (i.e. white cell fill and white font) - if I go into manage rules and add the white font and white fill it works fine, so not sure why it is not adding it via the macro. Can anyone help me with how to correct this please as I am stumped?

Thanks

Dave

sp_AnswersTopicSeeAnswer See Answer
Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 617
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
February 11, 2020 - 12:27 am
sp_Permalink sp_Print

Try this:

 

Sub Macro1()
'
' Macro1 Macro
'

'
Dim Colour
Colour = ActiveCell.Interior.Color
Application.ScreenUpdating = False
With Range("B5:AP75")
.Worksheet.EnableFormatConditionsCalculation = False
.Select
With .FormatConditions
.Delete
On Error Resume Next
ThisWorkbook.Names("GetColor").Delete
On Error GoTo 0
ThisWorkbook.Names.Add Name:="GetColor", RefersToR1C1:="=IdentifyColor(RC)"
Dim fc As Object
Set fc = .Add(Type:=xlExpression, Formula1:="=AND(GetColor<>0,GetColor<>14277081,GetColor<>10921638,GetColor<>255,GetColor<>" & Colour & ")")
End With
With fc
.SetFirstPriority
.Font.Color = RGB(255, 255, 255)
.Interior.Color = RGB(255, 255, 255)
.StopIfTrue = False
End With
.Worksheet.EnableFormatConditionsCalculation = True
End With
Range("B4").Select
End Sub

Function IdentifyColor(CellToTest As Range)
On Error Resume Next
IdentifyColor = CellToTest.Interior.Color

End Function

 

Note: it's probably going to perform badly since you have multiple udf calls per cell and conditional formatting is volatile. I suspect you'd be better off using VBA to apply direct formatting to the cells.

sp_AnswersTopicAnswer
Answers Post
Avatar
Dave MacIntyre
Member
Members
Level 0
Forum Posts: 7
Member Since:
April 30, 2019
sp_UserOfflineSmall Offline
3
February 11, 2020 - 7:55 pm
sp_Permalink sp_Print

That's perfect for what I need - thanks so much 🙂 It's only to be used to view certain coloured info and then switched off again, so it doesn't matter that it is slightly clunky as will only be used every now and then.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Aislinn Mellamphy, Lynnette Altomari, Roy Lutke, Dieneba NDIAYE, Darrell Hodge, Tucker Oakley
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Sopi Yuniarti
sandra parker
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Forum Stats:
Groups: 3
Forums: 24
Topics: 6214
Posts: 27243

 

Member Stats:
Guest Posters: 49
Members: 31894
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.