[SOLVED]I am trying to run the following code out of my personal workbook. It works on any new workbook I create, but not on any previous workbook (still xlsx) that I open.
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Sub HighlightRow()
' Highlight the entire row of the cell selected
Application.ScreenUpdating = False
' Remove the Conditional formatting and "screen updating" code from the active sheet (toggle off)
For i = 1 To Cells.FormatConditions.Count ' loops through all conditional formatting rules
If Cells.FormatConditions(i).Formula1 = "=CELL(""row"")=ROW()" Then
Cells.FormatConditions(i).Delete
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
On Error GoTo ExitS
.DeleteLines 1, [5]
End With
ExitS:
Exit Sub
On Error Resume Next
End If
Next i
' if the above rule is not found, inserts rule and "screen updating" code into activesheet (toggle on)
Cells.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=CELL(""row"")=ROW()"
Cells.FormatConditions(Cells.FormatConditions.Count).SetFirstPriority
With Cells.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
End With
Cells.FormatConditions(1).StopIfTrue = False
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
.InsertLines Line:=.CreateEventProc("SelectionChange", "Worksheet") + 1, _
String:=vbCrLf & " application.screenupdating = True"
End With
Application.VBE.MainWindow.Visible = False
Application.ScreenUpdating = True
End Sub
Sorry if this is a bit messy. Any help would be appreciated.
Bookmarks