VBA Excel 2007:需要在上面的每一行循环复制和循环计数,除了零

我是一个完整的白板,所以我在网上search整个代码,但现在看来,我打了长城,不能正确的。 我想要做的是:

  • 总结上面的每一行,并在上面添加额外的行(不知何故,我得到这个权利)
  • 在额外的行(我上面说)我要计算每个细胞以上的价值超过零(在Excel中,我使用简单的计数,如果公式,但我不能这样做在VBA)
  • 循环上面的步骤在本工作簿中的另一张表中除了表1(表的数量可能会有所不同,取决于input,所以我相信这可以通过循环完成,但我不知道如何)
  • 将上述步骤的输出复制到表单1中

这是我的代码到目前为止,因为我不能做循环我做了sheet2和sheet3 manualy。 我卡在第2步

这里是从@NEOman代码中修改的代码

Sub Copy_Sum() Dim ws As Worksheet 'Selecting the worksheets to loop through K = 1 For Each ws In ThisWorkbook.Worksheets 'Skiping the sheet1 If ws.Name <> "Sheet1" Then 'Counting the number of rows for automation rowscount = Cells(Rows.Count, 1).End(xlUp).Row temp = 0 'Looping throught the cells for the calculation For j = 2 To (rowscount) 'Counting the number of cells which value greater than zero If Cells(j, 9) > 0 Then temp = temp + 1 End If Next j 'Counting the number of rows for automation rowscount1 = Cells(Rows.Count, 1).End(xlUp).Row temp1 = 0 For i = 2 To (rowscount1) 'Counting the number of cells which value greater than zero If Cells(i, 10) > 0 Then temp1 = temp1 + 1 End If Next i 'Summing up the values which are above the current cell and in Sheet1, this inclues negative numbers as well Cells(rowscount + 1, 9).Value = Application.Sum(Range(Cells(1, 9), Cells(rowscount, 9))) Cells(rowscount + 2, 9) = temp 'copy ke sheet 1 Worksheets("Sheet1").Cells(K, 1).Value = Cells(rowscount + 1, 1).Value Worksheets("Sheet1").Cells(K, 2).Value = temp K = K + 1 Cells(rowscount1 + 1, 10).Value = Application.Sum(Range(Cells(1, 10), Cells(rowscount1, 10))) Cells(rowscount1 + 2, 10) = temp1 'copy ke sheet 1 Worksheets("Sheet1").Cells(rowscount1 + K, rowscount1 + 1).Value = Cells(rowscount1 + 2, 1).Value Worksheets("Sheet1").Cells(rowscount1 + K, rowscount1 + 2).Value = temp1 K = K + 1 End If Next ws End Sub 

我知道我的代码是一团糟,我在每一步写了评论,所以我知道代码在做什么。 我使用不同的代码列I和J,但都不工作:(。任何帮助将不胜感激,在此先感谢您的关注。

================================================== =========================================

代码必须运行在每个表(除了sheet1)manualy,所以即时通讯仍然试图使代码从sheet1运行,但工作在同一工作簿中的任何其他工作表。 任何帮助将不胜感激,提前感谢您的关注。

 Sub Copy_Sum() Dim ws As Worksheet 'Selecting the worksheets to loop through K = 1 For Each ws In ThisWorkbook.Worksheets 'Skiping the sheet1 If ws.Name <> "Sheet1" Then 'Counting the number of rows for automation rowsCount = Cells(Rows.Count, 1).End(xlUp).Row temp = 0 'Looping throught the cells for the calculation For j = 2 To (rowsCount) 'Counting the number of cells which value greater than zero If Cells(j - 1, 1) > 0 Then temp = temp + 1 End If Next j 'Summing up the values which are above the current cell and in Sheet1, this inclues negative numbers as well Cells(rowsCount + 1, 1).Value = Application.Sum(Range(Cells(1, 1), Cells(rowsCount, 1))) Cells(rowsCount + 1, 2) = temp Worksheets("Sheet1").Cells(K, 1).Value = Cells(rowsCount + 1, 1).Value Worksheets("Sheet1").Cells(K, 2).Value = temp K = K + 1 End If Next ws End Sub