行数据和列数据使用VBScript计数

如何使用VBScript我可以统计填充数据的行数和有多less列有特定行的值?

Col1 Col2 Col3 ........ColN-1 ColN+1...ColN+2.......ColN+2 Row1 AB Null Null Row2 1 2 Y . Row3 2 . Row4 PZ . . . . RowN-2 . RowN-1 TL Null.......Null RowN S RowN+1 Null ........(till the last column of the excel sheet that its version supprts.) 

所以在这里我需要的循环迭代,我将用于我的其他逻辑N是行和列是N + 1 更新

  Option Explicit Dim rg,CountBlank For C=0 to 10 Set rg = Ob6.Range(Ob6.Columns(c),Ob6.Columns(c)) CountBlank = objExcel1.Application.WorksheetFunction.CountBlank(rg) MsgBox("Column"&C": "&"Has"&(rg.rows.Count-CountBlank)) Next 

谢谢

试试这个让你开始。 它会为每行显示有数据的列数,每列显示有数据的行数。 然后您可以修改它以更适合您的需求:

编辑:代码更新捕获第一行/列只有1列/行的数据:

 Option Explicit Dim rg 'loop through columns For C=0 to 10 Set rg = Ob6.Columns(c) If objExcel1.Application.WorksheetFunction.CountA(rg) =1 Then Exit For End If Next MsgBox("Column" & C & " is first column with only 1 row") 'loop through rows For C=0 to 10 Set rg = Ob6.Rows(c) If objExcel1.Application.WorksheetFunction.CountA(rg) =1 Then Exit For End If Next MsgBox("Column" & C & " is first row with only 1 column")