1

如何使用 VBScript 我可以计算填充数据的行数以及有多少列具有特定行的值?

       Col1 Col2 Col3 ........ColN-1  ColN+1...ColN+2.......ColN+2

 Row1   A         B                             Null         Null
 Row2   1    2    Y                             .
 Row3        2                                  .
 Row4        P    Z 
  .                                             .
  .
  .
 RowN-2                                         .
 RowN-1                         T        L      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

谢谢

4

1 回答 1

1

试试这个让你开始。它将为每行显示包含数据的列数,并为每列显示包含数据的行数。然后,您可以对其进行修改以更适合您的需求:

编辑:更新代码以捕获只有 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")
于 2012-12-13T15:18:50.527 回答