1

How using VBScript I can count the number of rows filled with data and how many column has a value for a particular row?

       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.)

So here my required Loop iteration which i would use for my other logic is N for rows and for columns it would be N+1 Update

   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

Thanks

9
  • 2
    nice question, but please show us any efforts you've made to try to do this. We can help you get past your stuck points, but no one is really inclined to write a full script for you. Also, do you want vbscript? or are you wanting VBA (inside an XL application)? Commented Dec 13, 2012 at 14:06
  • VbScript i do want...But i don't have any idea how to do so? So here i posted.Please help me out. Commented Dec 13, 2012 at 14:25
  • 1
    You can use the oXLAp.WorksheetFunction.CountA(). I can give you an example but as Scott suggested, give it a try and then post back with what you tried and where are you stuck and we will take it from there :) Commented Dec 13, 2012 at 14:29
  • Have you written any vbscript to get yourself started? Commented Dec 13, 2012 at 14:31
  • I tried this one,But it can give only column data count. I don't have any idea about the row data count. Commented Dec 13, 2012 at 14:40

1 Answer 1

1

Try this to get you started. It will show for each row the number of columns that have data, and for each column the number of rows that have data. You can then modify it to more suit your needs:

EDIT: Code updated to capture first row / column with only 1 column / row of data:

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")
Sign up to request clarification or add additional context in comments.

3 Comments

I just modified my case description for you.Hope it will be helpful for you.But don't delete the code you posted right now.
Perfect!! Thanks for your help! I know you are the only people,can unstuck me from anywhere.:-)
Can you help me in my below post,where i have pasted the code i am using,but its too slow. And also I want those two codes to be combined into a single one.Please help me there. That is a bottleneck for me still. stackoverflow.com/questions/13835758/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.