我尝试使用R1C1格式和其他格式在A列的最后一行数据处停止边界,这将显示为“总体 - 总计”。
Sub Sumif_BD_Prem_Until_LastRow()
Dim LastRow As Long
Dim wb1 As Workbook
Set wb1 = Workbooks("macro all client v.01.xlsm")
LastRow = wb1.Sheets("CGIBill").Range("A:A").Find("Overall - Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastRow1 = wb1.Sheets("CGIBill").Range("A:A").Find("Overall - Total").Row
For i = 21 To LastRow
Cells(i, 19) = Application.SumIfs(wb1.Sheets("Detail").Range("T:T"), w wb1.Sheets("Detail").Range("K:K"), Cells(i, 3), wb1.Sheets("Detail").Range("M:M"), Cells(i, 9))
Next
With Sheets("CGIBill").Range("A20:V20" & LastRow1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
答案 0 :(得分:0)
问题在于您如何/在何处应用LastRow。您需要将20值替换为您计算的值。
所以如果你改变了
With Sheets("CGIBill").Range("A20:V20" & LastRow1).Borders
到
With Sheets("CGIBill").Range("A20:V" & LastRow1).Borders
你应该得到预期的结果。