I have some input data from my broker. I've written some code to automate calculations, adding columns and inserting some formulas.
In the end, I want to do some conditional formatting (affecting whole rows) to determine transactions that are profitable (green font whole row) and transactions that are lost (red font whole row).
To do this I've used USEDRANGE method - I know it's a tricky one, by my data are consistent - there's no empty rows, only few empty columns, so I think USEDRANGE will handle it. I need to use USEDRANGE because I'll have more rows next time I'll run this report.
But I have in my data the first row, where I keep headers 4 my columns.
I want my headers to stay black (font), but I still want to use USEDRANGE method.
How do I execute my conditional formatting using USEDRANGE method, excluding the first row (so it stays black font).
Option Explicit
Dim RowNumber As Long
Dim LastRow As Long
Dim ColumnNumber As Integer
Dim LastColumn As Integer
Dim VBA As Worksheet
Dim TotalRange As Range
Sub CondicionalFormating_WholeRows()
Set VBA = Workbooks("lista transakcji Dukascopy od October 2015.xlsm").Worksheets("VBA")
Set TotalRange = VBA.UsedRange
LastRow = VBA.Cells(Rows.Count, 1).End(xlUp).Row
LastColumn = VBA.Cells(1, Columns.Count).End(xlToLeft).Column
TotalRange.FormatConditions.Add Type:=xlExpression, Formula1:="=$H1<0"
TotalRange.FormatConditions(TotalRange.FormatConditions.Count).SetFirstPriority
With TotalRange.FormatConditions(1).Font
.Bold = False
.Italic = False
.Strikethrough = False
.Color = -16777024
.TintAndShade = 0
End With
TotalRange.FormatConditions(1).StopIfTrue = False
TotalRange.FormatConditions.Add Type:=xlExpression, Formula1:="=$H1>0"
TotalRange.FormatConditions(TotalRange.FormatConditions.Count).SetFirstPriority
With TotalRange.FormatConditions(1).Font
.Bold = False
.Italic = False
.Strikethrough = False
.ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.499984740745262
End With
TotalRange.FormatConditions(1).StopIfTrue = False
' VBA.Range(Cells(1, 1), Cells(LastRow, LastColumn)).Select
End Sub