Count Non Blank Rows

  • Thread starter Fredriksson via OfficeKB.com
  • Start date
F

Fredriksson via OfficeKB.com

I am trying to count the number of rows in a column that are non blank

Dim NumOfRows
Dim NumOfColumns
NumOfRows = CountA(Sheet1!$A:$A)
NumOfColumns = CountA(Sheet1!$2:$2)

the debugger keep erroring out at this line. Is there anouther function I
can use
 
M

merjet

NumOfRows = Application.CountA(Sheet1.Columns("$A:$A"))
NumOfColumns = Application.CountA(Sheet1.Rows("$2:$2"))

Hgth,
Merjet
 
T

Tom Ogilvy

Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA(Sheet1!$A:$A)
NumOfColumns = Application.CountA(Sheet1!$2:$2)
 
V

Vergel Adriano

try it this way:

With Worksheets("Sheet1")
NumOfRows = WorksheetFunction.CountA(.Range("A:A"))
NumOfColumns = WorksheetFunction.CountA(.Range("2:2"))
End With
 
F

Fredriksson via OfficeKB.com

Thanks I appreciate the help

Vergel said:
try it this way:

With Worksheets("Sheet1")
NumOfRows = WorksheetFunction.CountA(.Range("A:A"))
NumOfColumns = WorksheetFunction.CountA(.Range("2:2"))
End With
I am trying to count the number of rows in a column that are non blank
[quoted text clipped - 5 lines]
the debugger keep erroring out at this line. Is there anouther function I
can use
 
H

Helmut Weber

Hi Tom,

Sub Test447()
Msgbox = Application.CountA(Sheet1!$A:$A)
End Sub

First I get "Invalid character" and the first $-sign is highlighted.
After switching languages (english-german, german-english),
to and fro, I get syntax-error.

Maybe it has to do with localization.
Though I'm using an US-version,
date and time settings interfere every now and then.
When and why, nobody knows.

How would Application.CountA(Sheet1!$A:$A) look
when using cells(row,column) instead of $A:$A.

Help for CountA tells me:
The page cannot be displayed.

I'm lost.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
F

Fredriksson via OfficeKB.com

Thanks I appreciate the help
Tom said:
Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA(Sheet1!$A:$A)
NumOfColumns = Application.CountA(Sheet1!$2:$2)
I am trying to count the number of rows in a column that are non blank
[quoted text clipped - 5 lines]
the debugger keep erroring out at this line. Is there anouther function I
can use
 
J

Jim Rech

Try:

Application.CountA(Range("Sheet1!$A:$A"))

--
Jim
| Hi Tom,
|
| Sub Test447()
| Msgbox = Application.CountA(Sheet1!$A:$A)
| End Sub
|
| First I get "Invalid character" and the first $-sign is highlighted.
| After switching languages (english-german, german-english),
| to and fro, I get syntax-error.
|
| Maybe it has to do with localization.
| Though I'm using an US-version,
| date and time settings interfere every now and then.
| When and why, nobody knows.
|
| How would Application.CountA(Sheet1!$A:$A) look
| when using cells(row,column) instead of $A:$A.
|
| Help for CountA tells me:
| The page cannot be displayed.
|
| I'm lost.
|
| --
| Greetings from Bavaria, Germany
|
| Helmut Weber, MVP WordVBA
|
| Win XP, Office 2003
| "red.sys" & Chr$(64) & "t-online.de"
|
|
|
 
T

Tom Ogilvy

whoops -
I need to make another adjustment


Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA([Sheet1!$A:$A])
NumOfColumns = Application.CountA([Sheet1!$2:$2])

0r

Dim NumOfRows
Dim NumOfColumns
With Worksheets("Sheet1")
NumOfRows = Application.CountA(.range("A:A"))
NumOfColumns = Application.CountA(.Range("2:2"))


--
Regards,
Tom Ogilvy


Fredriksson via OfficeKB.com said:
Thanks I appreciate the help
Tom said:
Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA(Sheet1!$A:$A)
NumOfColumns = Application.CountA(Sheet1!$2:$2)
I am trying to count the number of rows in a column that are non blank
[quoted text clipped - 5 lines]
the debugger keep erroring out at this line. Is there anouther function I
can use
 
T

Tom Ogilvy

Unfortunately, I just focused on the first error I came to - see my followup
posting for a more complete response.
 
T

Tom Ogilvy

of course the With would need to be paired with an End With

Dim NumOfRows
Dim NumOfColumns
With Worksheets("Sheet1")
NumOfRows = Application.CountA(.range("A:A"))
NumOfColumns = Application.CountA(.Range("2:2"))
End With

--
Regards,
Tom Ogilvy


Tom Ogilvy said:
whoops -
I need to make another adjustment


Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA([Sheet1!$A:$A])
NumOfColumns = Application.CountA([Sheet1!$2:$2])

0r

Dim NumOfRows
Dim NumOfColumns
With Worksheets("Sheet1")
NumOfRows = Application.CountA(.range("A:A"))
NumOfColumns = Application.CountA(.Range("2:2"))


--
Regards,
Tom Ogilvy


Fredriksson via OfficeKB.com said:
Thanks I appreciate the help
Tom said:
Dim NumOfRows
Dim NumOfColumns
NumOfRows = Application.CountA(Sheet1!$A:$A)
NumOfColumns = Application.CountA(Sheet1!$2:$2)

I am trying to count the number of rows in a column that are non blank

[quoted text clipped - 5 lines]
the debugger keep erroring out at this line. Is there anouther function I
can use
 
F

Fredriksson via OfficeKB.com

Thanks for all of your help

Jim said:
Try:

Application.CountA(Range("Sheet1!$A:$A"))

| Hi Tom,
|
[quoted text clipped - 18 lines]
|
| I'm lost.
 
T

Tom Ogilvy

Jim's addendum would be excellent in almost every context.

Just as added explanation for Helmut, in my subsequent response, I didn't
choose that particular approach because it would be problematic in a sheet
module other than sheet1. The unqualified Range would be equivalent to
me.range and raise an error since the argument refers to a different sheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top