Public Function CalcSum()
Dim RowChar
Dim RowIdx
Dim PreIdx
Dim NowDir
Dim MaxCol
ColIdx = 2
RowChar = "B"
RowIdx = 0
PreIdx = 0
NowDir = ""
MaxCol = ActiveSheet.UsedRange.Rows.Count
'MaxCol = 10
Sum = 0
For row = 2 To MaxCol
Cells(row, ColIdx).Select
CellValue = Selection.Value
If IsEmpty(CellValue) Then
If RowIdx <> 0 Then
Cells(RowIdx, ColIdx + 1).Select
Selection.Value = Sum
Selection.Interior.Color = RGB(0, 255, 0)
MsgBox "Sum:" & Sum
Sum = 0
RowIdx = 0
End If
PreIdx = row
Else
RowIdx = PreIdx
Sum = Sum + CellValue
End If
Next
' Last Sum
If RowIdx <> 0 Then
Cells(RowIdx, ColIdx + 1).Select
Selection.Value = Sum
Selection.Interior.Color = RGB(0, 255, 0)
End If
CalcSum = "Done"
End Function
카테고리 없음
[VBA] Example
반응형
반응형