楼主 omnw |
Q:如何按照类别分区段统计发 票数量? A:将如下发 票明细整理成右侧的统计表,可以使用如下代码实现。
- Sub fapiao1()
- Dim i As Long
- Dim j As Long
- Dim k As Long
- Dim rng As Range
- For i = 3 To [A65536].End(xlUp).Row
- k = [H65536].End(xlUp).Offset(1, 0).Row
- If Cells(i, 2) <> Cells(i - 1, 2) Then
- Range("H" & k) = Cells(i, 2)
- Range("M" & k) = Cells(i, 5)
- Range("L" & k) = Cells(i, 4)
- Range("I" & k) = 1
- Range("J" & k) = Cells(i, 3)
- Else
- If Cells(i, 3) - Cells(i - 1, 3) = 1 And Cells(i, 5) = Range("M" & k - 1).Value Then
- Range("K" & k - 1) = Cells(i, 3)
- Range("I" & k - 1) = Range("I" & k - 1) + 1
- Range("L" & k - 1) = Range("L" & k - 1) + Cells(i, 4)
- Else
- Range("H" & k) = Range("H" & k - 1)
- Range("M" & k) = Cells(i, 5)
- Range("L" & k) = Cells(i, 4)
- Range("I" & k) = 1
- Range("J" & k) = Cells(i, 3)
- Range("K" & k) = Cells(i, 3)
- End If
- End If
- Next i
- End Sub
- Sub fapiao()
- Dim i As Long
- Dim j As Long
- Dim k As Long
- Dim rng As Range
- For i = 3 To [A65536].End(xlUp).Row
- k = [H65536].End(xlUp).Offset(1, 0).Row
- If Cells(i, 2) <> "" Then
- Range("H" & k) = Cells(i, 2)
- Range("M" & k) = Cells(i, 5)
- Range("L" & k) = Cells(i, 4)
- Range("I" & k) = 1
- Range("J" & k) = Cells(i, 3)
- Else
- If Cells(i, 3) - Cells(i - 1, 3) = 1 And Cells(i, 5) = Range("M" & k - 1).Value Then
- Range("K" & k - 1) = Cells(i, 3)
- Range("I" & k - 1) = Range("I" & k - 1) + 1
- Range("L" & k - 1) = Range("L" & k - 1) + Cells(i, 4)
- Else
- Range("H" & k) = Range("H" & k - 1)
- Range("M" & k) = Cells(i, 5)
- Range("L" & k) = Cells(i, 4)
- Range("I" & k) = 1
- Range("J" & k) = Cells(i, 3)
- Range("K" & k) = Cells(i, 3)
- End If
- End If
- Next i
- End Sub
|