从USEDRANGE方法中排除第一行(它是我的表中的第一行)?

我有一些来自我的经纪人的input数据。 我写了一些代码来自动化计算,添加列和插入一些公式。

最后,我想做一些条件格式(影响整个行),以确定有利可图的交易(绿色字体整行)和交易丢失(红色字体整行)。

要做到这一点,我已经使用了USEDRANGE方法 – 我知道这是一个棘手的方法,我的数据是一致的 – 没有空行,只有less数空列,所以我认为USEDRANGE将处理它。 我需要使用USEDRANGE,因为下次运行这个报告时会有更多的行。

但是,我在我的数据第一行,我保持在我的列4。

我想我的头保持黑色(字体),但我仍然想使用USEDRANGE方法。

在这里输入图像说明

如何执行使用USEDRANGE方法的条件格式,不包括第一行(所以它保持黑色字体)。

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 

 Set TotalRange = VBA.UsedRange '<<< your existing line 'Add this line right after Set TotalRange = TotalRange.Offset(1,0).Resize(TotalRange.Rows.Count-1, _ TotalRange.Columns.Count) 

使用.offset(1)将整个范围参考向下移动1行。 这将在范围的末尾留下一个空行。 .Resize(VBA.UsedRange.Rows.Count - 1).Resize(VBA.UsedRange.Rows.Count - 1)最后一行。


 Set TotalRange = VBA.UsedRange.Offset(1).Resize(VBA.UsedRange.Rows.Count  -  1)