VBA Error with Color

jmarting13

New Member
Joined
Mar 2, 2021
Messages
39
Platform
  1. Windows
Whenever I run the code attached. I keep getting an error on the line "Font.color = vbRed". I've also tried typing it as "Target.font.color = RGB(255, 0, 0)" but that doesn't work either. Please help!!

Private Sub Worksheet_Calculate()
Dim Xrg As Range
Set Xrg = Range("K1")
If Not Intersect(Xrg, Range("K1")) Is Nothing Then
MsgBox "This is fun"
Range("A1:J37").Font.Color = vbBlack
End If


If Range("K1").Value = "Quote" Then
Font.Color = vbBlack
Else
Font.Color = vbRed
End If
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Font is a property of a range so you need to qualify Font with the range you are applying it to. Given that, your last If..Then block should be written this way...
VBA Code:
If Range("K1").Value = "Quote" Then
  Range("K1").Font.Color = vbBlack
Else
  Range("K1").Font.Color = vbRed
End If
End Sub
 
Upvote 0
Font is a property of a range so you need to qualify Font with the range you are applying it to. Given that, your last If..Then block should be written this way...
VBA Code:
If Range("K1").Value = "Quote" Then
  Range("K1").Font.Color = vbBlack
Else
  Range("K1").Font.Color = vbRed
End If
End Sub
Ok. How would I write the code if I wanted only my future additions to be red? I basically just want everything I type in to be red, not specific cells.
 
Upvote 0

Forum statistics

Threads
1,215,226
Messages
6,123,734
Members
449,116
Latest member
alexlomt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top