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 回答