VBA - Counting the number of cells filled in row

4

Hello everyone. I'm trying to create a code responsible for reading the number of cells filled in the rows .. I tried this way but I was not successful.

  For b = 1 To rMaior
         contador = Worksheets("1").Range("b:b").Cells.SpecialCells(xlCellTypeConstants).Count
                MsgBox contador
  Next b

Thank you.

    
asked by anonymous 10.11.2015 / 13:55

2 answers

3

Hello,

I think your formula has a small error ... try using the name of the worksheet as below:

MsgBox Plan1.Range("b:b").Cells.SpecialCells(xlCellTypeConstants).Count

I hope I have helped!

    
10.11.2015 / 20:58
1

Change your code to this:

  For b = 1 To rMaior
         contador = Worksheets("1").Rows(b).Cells.SpecialCells(xlCellTypeConstants).Count
         MsgBox contador
  Next b

This code assumes that you want to count n lines of the worksheet called 1. In addition, you must have a variable called rMaior declared and specifying the last line to be counted. Thus, the code will go from line 1 to rMore counting the number of non-empty cells per line.

    
12.11.2015 / 12:50