Heya,
I'm working on some code to highlight the ActiveCell's row and column by using the Worksheet_SelectionChange() sub using conditional formatting, but I've run into some snags when I set any of the font properties for the second conditional format.
After lots of trial and error, I seem to have narrowed down the problem, but it doesn't help me figure out how to solve it. When I run the code below, I get either "Runtime error 1004: Unable to Set the Bold property of the Font class" or "Runtime error 1004: Application-definied or object-defined error" when I get to the .Font.Bold=True line under With ActiveCell.EntireRow line.
I've tried setting other Font properties and they all give me similar errors. It obviously works fine if I'm working with the Interior property to change the fill color, so it does seem to be related to the Font class under the FormatConditions. However, it works fine with the first conditional format. Also, I found out that setting the font property on the second conditional format works fine if it's the same range as the first conditional format. (e.g. Using EntireColumn for both of them instead of EntireRow for the second conditional format.) So it also seems to be related to working with two different ranges in my code.
Obviously, since I'm planning on putting this in my Worksheet_SelectionChange() sub, I can't exactly change my selection in my code else I'll end calling the function and getting into an infinite loop. (Why yes, I might know this bit from my own experiences in solving this, LOL.) I also know I can do the highlighting with using regular formatting instead of conditional formatting, but then I'd have to delete all the formatting in the sheet each time I select a different cell and I don't necessarily want to do that with my spreadsheet.
I'm using Excel 2007 and I tried it on both a Windows XP and a Windows 7 computer and I get the Runtime error in the same place with both machines. Anyone seen anything like this? Any ideas I might be able to try to make this work?
Thanks, I really appreciate any help I get!
I'm working on some code to highlight the ActiveCell's row and column by using the Worksheet_SelectionChange() sub using conditional formatting, but I've run into some snags when I set any of the font properties for the second conditional format.
After lots of trial and error, I seem to have narrowed down the problem, but it doesn't help me figure out how to solve it. When I run the code below, I get either "Runtime error 1004: Unable to Set the Bold property of the Font class" or "Runtime error 1004: Application-definied or object-defined error" when I get to the .Font.Bold=True line under With ActiveCell.EntireRow line.
Code:
Sub ChangingFontColumnAndRow()
Cells.FormatConditions.Delete
ActiveCell.EntireColumn.FormatConditions.Add Type:=xlExpression, Formula1:="=TRUE"
ActiveCell.EntireColumn.FormatConditions(ActiveCell.EntireColumn.FormatConditions.Count).SetFirstPriority
With ActiveCell.EntireColumn.FormatConditions(1)
.Interior.Color = 16304054
.Font.Color = -65536
End With
ActiveCell.EntireColumn.FormatConditions(1).StopIfTrue = False
ActiveCell.EntireRow.FormatConditions.Add Type:=xlExpression, Formula1:="=TRUE"
ActiveCell.EntireRow.FormatConditions(ActiveCell.EntireRow.FormatConditions.Count).SetFirstPriority
ActiveCell.EntireRow.FormatConditions(1).StopIfTrue = False
With ActiveCell.EntireRow.FormatConditions(1)
.Interior.Color = 16304054
.Font.Bold = True
End With
End Sub
Obviously, since I'm planning on putting this in my Worksheet_SelectionChange() sub, I can't exactly change my selection in my code else I'll end calling the function and getting into an infinite loop. (Why yes, I might know this bit from my own experiences in solving this, LOL.) I also know I can do the highlighting with using regular formatting instead of conditional formatting, but then I'd have to delete all the formatting in the sheet each time I select a different cell and I don't necessarily want to do that with my spreadsheet.
I'm using Excel 2007 and I tried it on both a Windows XP and a Windows 7 computer and I get the Runtime error in the same place with both machines. Anyone seen anything like this? Any ideas I might be able to try to make this work?
Thanks, I really appreciate any help I get!