我正在清理文件,我正在尝试将值合并在一起,但总和总是等于零。我的代码给出了正确的范围,并进行了正确的格式化...只是不能得到总和来显示除了0之外的任何内容。
Sub AddBlankRows()
'
Dim iRow As Integer, iCol As Integer
Dim oRng As Range
Dim fRow As Integer
Set oRng = Range("e2")
iRow = oRng.Row
iCol = oRng.Column
fRow = iRow
Do
'
If Cells(iRow + 1, iCol) <> Cells(iRow, iCol) Then
Cells(iRow + 1, iCol).EntireRow.Insert shift:=xlDown
iRow = iRow + 1
Range("k" & iRow).Font.Bold = True
Range("k" & iRow).Value = "Total"
Range("l" & iRow).Font.Bold = True
Range("l" & iRow).Formula = "=sum(l" & CStr(fRow) & ":l" & CStr(iRow) & ")"
iRow = iRow + 1
fRow = iRow
Else
iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, iCol).Text = ""
'
End Sub
答案 0 :(得分:0)
您在"=sum(l" & CStr(fRow) & ":l" & CStr(iRow) & ")"
Sum
公式单元格包含在和范围内。
将此更改为
"=sum(l" & CStr(fRow) & ":l" & CStr(iRow-1
)& ")"
,应该有用。