• 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

Changing shape colours|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Changing shape colours|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 & MacrosChanging shape colours
sp_PrintTopic sp_TopicIcon
Changing shape colours
Avatar
John Langham-Service
Member
Members
Level 0
Forum Posts: 51
Member Since:
July 17, 2018
sp_UserOfflineSmall Offline
1
March 18, 2023 - 3:50 am
sp_Permalink sp_Print

Hi I have a sheet with a lot of shapes on some of whic I am using as buttons I tried a short piece of code to fade the text of the clicked shape but it gives a type mismatch error on the If line

 

Sub ClickedBtn()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name = "btn_Hetton" Or "btn_GMH" Or "btn_Kibi" Or "btn_MHarb" Or "btn_All" Then
shp.Fill.BackColor.RGB = RGB(0, 0, 0)
Else
End If

Next shp
ActiveSheet.Shapes(Application.Caller).Fill.BackColor.RGB = RGB(192, 192, 192)

End Sub

sp_AnswersTopicSeeAnswer See Answer
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
March 18, 2023 - 11:23 am
sp_Permalink sp_Print

Hi,

Please supply your file so we don't have to recreate it.

Thanks

Phil

Avatar
John Langham-Service
Member
Members
Level 0
Forum Posts: 51
Member Since:
July 17, 2018
sp_UserOfflineSmall Offline
3
March 20, 2023 - 6:47 pm
sp_Permalink sp_Print

File attached it has links to ther files so graphs wont change but everything else should work

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 625
Member Since:
November 1, 2018
sp_UserOnlineSmall Online
4
March 20, 2023 - 7:28 pm
sp_Permalink sp_Print

You can't write Or criteria like that - you have to repeat the test of the shape name each time.

If shp.Name = "btn_Hetton" Or shp.Name = "btn_GMH" Or shp.Name = "btn_Kibi" Or shp.Name = "btn_MHarb" Or shp.Name = "btn_All"

Alternatively, use a Select Case construction:

 

For Each shp In ActiveSheet.Shapes
Select Case shp.Name
Case "btn_Hetton", "btn_GMH", "btn_Kibi", "btn_MHarb", "btn_All"
shp.Fill.BackColor.RGB = RGB(0, 0, 0)
Case Else
' do nothing
End Select

Next shp

sp_AnswersTopicAnswer
Answers Post
Avatar
John Langham-Service
Member
Members
Level 0
Forum Posts: 51
Member Since:
July 17, 2018
sp_UserOfflineSmall Offline
5
March 21, 2023 - 2:26 am
sp_Permalink sp_Print

Thanks,

I tried with the case select but it doesnt appear to do anything it runs but doesnt change font and skips over the Application.Caller Shape

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 625
Member Since:
November 1, 2018
sp_UserOnlineSmall Online
6
March 21, 2023 - 3:51 am
sp_Permalink sp_Print

There is no code there to change font?

 

Application.Caller will only work if the code is called by clicking a button.

Avatar
Hans Hallebeek
the Netherlands
Member
Members
Level 0
Forum Posts: 73
Member Since:
October 17, 2018
sp_UserOfflineSmall Offline
7
March 21, 2023 - 5:54 pm
sp_Permalink sp_Print

And the file will also not work if there are unresolved references because it points either to a renamed file of an entire different file.

When posting a file make sure it works for the perosons outside your environment

e.g.

 

='Z:\Daten\5_Werksorganisation\2_QS\MGB_5\7_Complaints\Customer\Copy of Customer Complaint Log 20222.xlsx'!CompLog[Comp number]

Avatar
John Langham-Service
Member
Members
Level 0
Forum Posts: 51
Member Since:
July 17, 2018
sp_UserOfflineSmall Offline
8
March 22, 2023 - 8:20 pm
sp_Permalink sp_Print

I mistyped its the back color thats supposed to change, but I now changed it to forecolor and it works.

thanks

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, Nada Perovic, Denise Lloyd
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
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.