VBA表格数据中的嵌套循环

我有一个非常彻底的search,但我仍然在这个问题挣扎。 基本上,我有一个各种标题的列表,其中每个标题有10个相应的variables,可能有也可能没有数据点。

表

我想循环遍历第一列,用循环遍历每一行的嵌套循环来计数和logging每个填充的数据点的数量。 大多数我不知道如何在第二个循环中引用单元格。 任何帮助将不胜感激!

我真的不明白你的最终目标,但我希望下面的代码将帮助你去正确的方向。

据我了解,我写了一个代码,COUNT有多less个单元格,每行有数据。

我不确定这是否是你想要的,但让我知道,我会编辑我的代码,以满足您的要求。

选项显式

 Sub test() Dim wb As Workbook Dim ws As Worksheet Dim Lastrow As Long Dim i As Long, j As Long, c As Long Set wb = ThisWorkbook Set ws = wb.Sheets("Sheet1") ' Change the name of your worksheet Lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row ' Find the las row With ws For i = 1 To Lastrow 'Start at row 1 until the last row c = 0 For j = 2 To 11 ' 10 Variables (until the column "L") If Not IsEmpty(.Cells(i, j)) Then c = c + 1 ' Count and record the number of populated data points in each columns Next j .Cells(i, 12).Value = c 'Past the result in column "L" Next i End With End Sub