Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel查找循环中每6列的总和_Excel_Vb.net - Fatal编程技术网

Excel查找循环中每6列的总和

Excel查找循环中每6列的总和,excel,vb.net,Excel,Vb.net,我有一个excel工作表,我已经通过宏插入了空白列,但现在我需要找到每6列的总和,并将值存储在空白列中?尝试从7步到7步,但不起作用。 我需要空列来获得最后6列的平均值 我试过的代码是 Sub sum_of_every_6th_column() Dim iLastCol as Integer iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column ' same as CTRL+RIGHT ARROW For

我有一个excel工作表,我已经通过宏插入了空白列,但现在我需要找到每6列的总和,并将值存储在空白列中?尝试从7步到7步,但不起作用。 我需要空列来获得最后6列的平均值

我试过的代码是

Sub sum_of_every_6th_column() 
    Dim iLastCol as Integer 
    iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column ' same as CTRL+RIGHT ARROW 
    For colx = 7 To iLastCol Step 8 '?? Unable to understand what can come here 
    Next 
End Sub

尝试此代码,根据您的需要进行更改

Sub sumCols()
Dim i As Long, j As Long, k As Long
j = 0
For k = 1 To Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To Cells(k, Columns.Count).End(xlToLeft).Column + 1
    If IsEmpty(Cells(k, i)) Then
        Cells(k, i) = j
        j = 0
    Else
        j = j + Cells(k, i)
    End If
Next i
Next k
End Sub

你的代码的哪一部分不起作用?在你的循环中向我们展示你的代码片段将非常有帮助。我尝试合并此代码,但我无法正确获取值?每个第6列的子和()dim iLastCol作为整数iLastCol=单元格(1,Columns.Count)。End(xlToLeft).Column'与colx=7到iLastCol步骤8的CTRL+右箭头相同??无法理解下一步会发生什么,苏比编辑了您的问题,将您评论中的代码包括在内。您确定这是VB.Net吗?它看起来更像VBA(Excel宏中使用的语言)。如果是VBA,则应编辑问题以用VBA标记替换vb.net标记。