通过列添加数字

时间:2018-08-20 11:08:01

标签: vba excel-vba

我想编写代码,将两列中的2行分开的数字相加。在第4行和第6行上,我存储了一个输入数字的数组,我想将它们之间的总和结果分别返回到B列到F列的第7行。我在指定要输入的行的内容时遇到问题添加,因此,我得到一个错误。我当时想从对行(只有一行)进行人工循环开始,然后遍历各列。在定义输入数字的行(即第4和第6行的值)时出现错误。

Sub SumCol()
Dim StartRow As Integer, EndRow As Integer, answer As Integer, FirstInput As Integer, FirstInputRow As Integer, SecondInput As Integer, SecondInputRow As Integer

Dim ColumnNo As Integer, TargetRow As Integer
Const COLUMNSTART As Integer = 2
Const COLUMNEND As Integer = 6

TargetRow = 7
EndRow = 7
FirstInputRow = 3
SecondInputRow = 6
FirstInput = Cells(FirstInputRow, ColumnNo)
SecondInput = Cells(SecondInputRow, ColumnNo)

For StartRow = TargetRow To EndRow
    For ColumnNo = COLUMNSTART To COLUMNEND
    answer = FirstInput + SecondInput
    Cells(TargetRow, ColumnNo).Value = answer
    Next ColumnNo

    TargetRow = TargetRow + 1
Next StartRow

End Sub

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

简单的事情

var policy = Policy.Handle<HttpRequestException>()
                   .WaitAndRetryForever(retryAttempt => TimeSpan.FromMinutes(1));

var response = await policy.ExecuteAsync(async () => await DoApiCallAsync()
                           .ConfigureAwait(false));

return response;

不能解决您的问题?很简单!也许我不完全了解您的目标...