如何使用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
由于
答案 0 :(得分: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")