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)

0に設定nしているため、常に 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 に答える