#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Count rows

Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Count rows

Hi
in your case remove the space between the apostrophes:
Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < ""
iCount = iCount + 1
Wend
End Sub


Or use
icount=application.counta(range("B:B"))


--
Regards
Frank Kabel
Frankfurt, Germany


Hugh wrote:
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Count rows



--

HTH

RP

"Hugh" wrote in message
...
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.


























  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Count rows

Hugh,

Don't test for a space

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < ""
iCount = iCount + 1
Wend
End Sub

--

HTH

RP

"Hugh" wrote in message
...
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.


























  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Count rows

Hugh

I think:

While Sheet1.Range("B" & iCount).Value < ""

Note that the quotes are together as opposed to having a space in between.

Assuming that your data starts in row 1 and you want the last cell in column
B, you could use:

Dim iCount as Long
iCount = Range("B" & Rows.Count).End(xlUp).Row

That would be quicker if you have a lot of rows/cells to check.

Regards

Trevor


"Hugh" wrote in message
...
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.





  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Count rows

Thanks all for your reply. I did use "" instread of " "
before I asked help but it did not work. Now I know why
since data row was not started from row 1. The question
is than how to detect first data row? Thanks very much.

Hugh

-----Original Message-----
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Count rows

Thank all for your help. I used "" instead of " " before I
asked help. It did not work and now I know why since my
data rows was not started from row 1. The question is
then: how to detect first data row? Thanks again.


-----Original Message-----
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Count rows

First data row

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value = " "
iCount = iCount + 1
Wend
End Sub


--

HTH

RP

"Hugh" wrote in message
...
Thank all for your help. I used "" instead of " " before I
asked help. It did not work and now I know why since my
data rows was not started from row 1. The question is
then: how to detect first data row? Thanks again.


-----Original Message-----
Hi there,

How to count data rows? I tried following sub. It did not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























.



  #9   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Count rows

Hi Bob,

Thanks very much for your help. Your method works fine.
You might mistyped " ". It should be "".

Hugh

-----Original Message-----
First data row

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value = " "
iCount = iCount + 1
Wend
End Sub


--

HTH

RP

"Hugh" wrote in

message
...
Thank all for your help. I used "" instead of " "

before I
asked help. It did not work and now I know why since my
data rows was not started from row 1. The question is
then: how to detect first data row? Thanks again.


-----Original Message-----
Hi there,

How to count data rows? I tried following sub. It did

not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























.



.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Count rows

Lol. After I made the same comment earlier as well.

--

HTH

RP

wrote in message
...
Hi Bob,

Thanks very much for your help. Your method works fine.
You might mistyped " ". It should be "".

Hugh

-----Original Message-----
First data row

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value = " "
iCount = iCount + 1
Wend
End Sub


--

HTH

RP

"Hugh" wrote in

message
...
Thank all for your help. I used "" instead of " "

before I
asked help. It did not work and now I know why since my
data rows was not started from row 1. The question is
then: how to detect first data row? Thanks again.


-----Original Message-----
Hi there,

How to count data rows? I tried following sub. It did

not
work.

Private Sub CountRows()
Dim iCount As Long
iCount = 1
While Sheet1.Range("B" & iCount).Value < " "
iCount = iCount + 1
Wend
End Sub

Thanks in advance for your help.
























.



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count all rows in column with data, Except rows 1-5 Gregory Day Excel Worksheet Functions 4 March 27th 08 02:58 PM
match week, count rows, sum rows? earls Excel Worksheet Functions 2 January 5th 07 02:34 AM
Count number of rows, where non relevant rows are hidden Pieter Excel Discussion (Misc queries) 2 November 8th 06 12:24 PM
Count rows and insert number to count them. Mex Excel Discussion (Misc queries) 6 August 23rd 06 02:29 AM
Why does rngDataSource.Rows.Count = 65536 when worksheet Rows=95? [email protected] Excel Discussion (Misc queries) 12 July 22nd 05 12:50 PM


All times are GMT +1. The time now is 07:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"