0

このマクロを単一行のセルではなく列全体で実行する方法を誰か説明してもらえますか? つまり、個々のセルの値をチェックし、その行のそれぞれのセルで必要な計算と出力を実行します。

Sub Calculate_Costs()
If Cells(2, 7) = "One Man" And Cells(2, 6) >= Cells(2, 5) Then
Cells(2, 8) = 6.5 + ((Cells(2, 6) - 20) * 0.23)
ElseIf Cells(2, 7) = "One Man" And Cells(2, 6) < Cells(2, 5) Then
Cells(2, 8) = 6.5 + ((Cells(2, 5) - 20) * 0.23)
ElseIf Cells(2, 7) = "Two Man" And Cells(2, 6) >= Cells(2, 5) Then
Cells(2, 8) = 38 + ((Cells(2, 6) - 50) * 0.38)
ElseIf Cells(2, 7) = "Two Man" And Cells(2, 6) < Cells(2, 5) Then
Cells(2, 8) = 38 + ((Cells(2, 5) - 50) * 0.38)
Else
Cells(2, 14) = "This is not working"
End If
End Sub
4

1 に答える 1

0

何かのようなもの:

Dim row As Integer
row = 1
While Cells(row, 7) <> ""
    //Your original code here but with 2 replaced with row
    row = row + 1
Wend

空白のセルに到達するまで、列 7 のすべての行をループします。

于 2013-02-14T22:40:23.347 に答える