我需要运行一个循环,检查A列中的单元格是否不为空,然后它将B列放在同一行中的整数并将其求和为前一个整数,当A列中的单元格为空时,它将将在B列的下一行中打印总和。
X = 0
For myCounter = myRow To 1 Step -1
Do While Not IsEmpty(Cells(myCounter + 1, 1).Value)
X = Cells (myCounter,10).Value + X
Loop
答案 0 :(得分:0)
您可以尝试:
Option Explicit
Sub test()
Dim LastRow As Long, i As Long
'Set you sheet
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Start from row 2
For i = 2 To LastRow
If Not IsEmpty(.Range("A" & i).Value) Then
.Range("B" & i - 1).Value = .Range("B" & i).Value + .Range("B" & i - 1).Value
Else
.Range("B" & i + 1).Value = .Range("B" & i).Value
End If
Next i
End With
End Sub
答案 1 :(得分:0)
这就是我需要的 enter image description here