1

我有以下代码:

Case "END-BOX"
    EndBox = ActiveCell.Row
    Selection.Offset(-1, 2).Select
    Selection.ClearContents
    Rows(2).Insert Shift:=xlDown
    TotalCols = ActiveSheet.UsedRange.Columns.Count

    Col = 4
    Cells(EndBox, Col).Select
    For i = EndBox To 1 Step -1
        If Cells(i, Col).Value <> "" Then
            n = n + 1
        Else
            Cells(i, Col).Value = n
            If Cells(i, Col).Offset(0, -2).Value = "NEW-BOX" Then Cells(i, Col).Interior.ColorIndex = 4
            n = 0
        ' Application.Speech.Speak (n)
        End If
    Next

    Range(EndBox).Select
    Selection.Offset(1, -2).Select

我想弄清楚如何在计算总和后自动读出最终的总和数,但是这个循环给我带来了麻烦,我不明白我将如何实现它。任何帮助将不胜感激。

4

1 回答 1

0

n = 0

' Application.Speech.Speak (n)

您设置n为 0,因此您将始终得到 0。

把它放在后面Next得到最终值n

For i = EndBox To 1 Step -1
    If Cells(i, Col).Value <> "" Then
        n = n + 1
    Else
        Cells(i, Col).Value = n
        If Cells(i, Col).Offset(0, -2).Value = "NEW-BOX" Then Cells(i, Col).Interior.ColorIndex = 4
        n = 0
    End If
Next
Application.Speech.Speak (n)
于 2013-02-20T16:30:05.253 回答