Apologies
@Joe4 and thank you for your help on this. I am in the middle of doing what you suggested from the other post that was closed and am still getting the application-defined or object-defined error and then it points to either this line cell.Font.Color = -16776961 or this line cell.Font.ColorIndex = xlAutomatic depending on if the button is set for red or black font color. Would you know why this is happening? I usually do test the code in a fresh blank spreadsheet just to make sure its working before I apply it to the spreadsheet I need it to work in. I know you mentioned it worked flawless for you but not sure what I am doing wrong. Here is what I have in the Sheet1 change event:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim cell As Range
' See if any cells updates in watched range
Set rng = Intersect(Target, Range("A1:C10"))
If rng Is Nothing Then Exit Sub
' Loop through newly updated cells in watched range
For Each cell In rng
If Range("Z1") = "Red" Then
cell.Font.Color = -16776961
Else
cell.Font.ColorIndex = xlAutomatic
End If
Next cell
End Sub
Then this is what I have assigned to the button:
Sub font_color()
If Range("Z1") = "Black" Then
Range("Z1") = "Red"
Else
Range("Z1") = "Black"
End If
ActiveSheet.Unprotect "hello"
ActiveSheet.Shapes.Range(Array("Button 1")).Select
If Selection.Characters.Text = "BLACK" Then
With Selection.Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
'.TintAndShade = 0
'.ThemeFont = xlThemeFontMinor
End With
With Selection.Font
.Color = -16776961
'.TintAndShade = 0
End With
Selection.Characters.Text = "RED"
With Selection.Characters(Start:=1, Length:=3).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
End With
ActiveSheet.Protect "hello"
Exit Sub
End If
ActiveSheet.Unprotect "hello"
ActiveSheet.Shapes.Range(Array("Button 1")).Select
If Selection.Characters.Text = "RED" Then
With Selection.Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
'.TintAndShade = 0
'.ThemeFont = xlThemeFontMinor
End With
With Selection.Font
.ColorIndex = xlAutomatic
'.TintAndShade = 0
End With
Selection.Characters.Text = "BLACK"
With Selection.Characters(Start:=1, Length:=5).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
ActiveSheet.Protect "hello"
End If
End Sub
Another odd thing that I found is that I could not rename the button to another name. I wanted to change it from Button 1 to font_color but it kept reverting back and so I adjusted the code to show Button 1 as the name of the button. The button seems to function as far as holding the word "Red" or "Black" in the Z1 cell and also changing the word on the button itself from "RED" to "BLACK" but thats about it. I just never had a problem renaming a button before. Every time I try it just pops the VBA window and shows the code for the button.