Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default count of items in columns

I know this is simple but finding it seems to elude me. There must be an
Excel function that will return the count of cells in a column that contain
any value. they will be filled from the top down with no blanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default count of items in columns

That would either be Count or CountA depending on the type of data in
the cell.
Count:
Counts the number of cells that contain numbers and numbers within the
list of arguments. Use COUNT to get the number of entries in a number
field in a range or array of numbers. Syntax COUNT(value1,value2, ...)
CountA:
Counts the number of cells that are not empty and the values within the
list of arguments. Use COUNTA to count the number of cells that contain
data in a range or array. Syntax COUNTA(value1,value2, ...)

Hope this helps

Arnold Klapheck wrote:
I know this is simple but finding it seems to elude me. There must be an
Excel function that will return the count of cells in a column that contain
any value. they will be filled from the top down with no blanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default count of items in columns

I have tried, . . . I should have said I need a way to use it
in vba

Range("a1").Select
Num = Row.Count ' or Rows.Count

but I end up with Num = 65536 when their are only 5 items in the column

I saw someone else's code of

Num = Cells(Rows.Count, LoopCount).End(xlUp).Row - 1

that seems to work, I use it in a loop, and it ignores header, I was
wondering if their was a simpler way.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default count of items in columns

There are a lot of ways:

Sub TryNow()
Dim num As Long

num = Range("A1", Range("A1").End(xlDown)).Rows.Count
MsgBox num

num = Cells(Rows.Count, 1).End(xlUp).Row
MsgBox num

num = Application.CountA(Range("A:A"))
MsgBox num

End Sub

HTH,
Bernie
MS Excel MVP


"Arnold Klapheck" wrote in message
...
I have tried, . . . I should have said I need a way to use it
in vba

Range("a1").Select
Num = Row.Count ' or Rows.Count

but I end up with Num = 65536 when their are only 5 items in the column

I saw someone else's code of

Num = Cells(Rows.Count, LoopCount).End(xlUp).Row - 1

that seems to work, I use it in a loop, and it ignores header, I was
wondering if their was a simpler way.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default count of items in columns

=COUNT(range) counts cells in range that have numeric values
=COUNTA(range) counts all non-blank cells - we aware that a formula (eg
=IF(A1),A1, "") that returns a blank will be counted by COUNTA.

This message should have been posted to the Excel.Mics newsgroup - this on
is for Visual Basic questions but not to worry!

best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Arnold Klapheck" wrote in
message ...
I know this is simple but finding it seems to elude me. There must be an
Excel function that will return the count of cells in a column that
contain
any value. they will be filled from the top down with no blanks.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default count of items in columns

Try this

Sub mycount()
Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.CountA(myRange)
MsgBox answer
End Sub

--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Arnold Klapheck" wrote in
message ...
I know this is simple but finding it seems to elude me. There must be an
Excel function that will return the count of cells in a column that
contain
any value. they will be filled from the top down with no blanks.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default count of items in columns

Try this
Sub mycount()
Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.CountA(myRange)
MsgBox answer
End Sub

but what if I don't know if MyRange ends at C10?

I Think I found a solution and I don't have to worry about blanks. If anyone
can think of a way to make more efficient I would be interested.

Function FindMaxRows(Optional strwrks As String) As Integer
'Returns the number of the last row with data regardless of blanks
in-between
Sheets(strwrks).Select
Dim wb As Workbook
Dim wrks As Worksheet
Set wb = Application.ActiveWorkbook
Set wrks = wb.ActiveSheet
FindMaxRows = wrks.Cells.Find(What:="*", After:=wrks.Range("A1"), _
Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
End Function

Function FindMaxColumns(Optional strwrks As String) As Integer
'Returns the number of the last Column with data regardless of blanks
in-between
Sheets(strwrks).Select
Dim wb As Workbook
Dim wrks As Worksheet
Set wb = Application.ActiveWorkbook
Set wrks = wb.ActiveSheet
FindMaxColumns = wrks.Cells.Find(What:="*", After:=wrks.Range("A1"), _
Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, MatchCase:=False).Column
End Function
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
line up items in column a with items in columns b, c, etc meera123 Excel Discussion (Misc queries) 0 September 2nd 08 02:20 PM
Count items by day Amber Excel Worksheet Functions 5 October 23rd 07 04:40 PM
SUMPRODUCT to count items with duplicates where another column contains two defined items PCLIVE Excel Worksheet Functions 4 September 8th 07 10:33 AM
How can I count items in multiple columns with different criteria. ChileRed Excel Worksheet Functions 0 March 21st 06 07:15 PM
count non bolded items Annette[_4_] Excel Programming 2 December 20th 04 08:31 PM


All times are GMT +1. The time now is 09:53 AM.

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

About Us

"It's about Microsoft Excel"