Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default counting records

can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default counting records

Hi Panagiotis,

Try:

'=============
Public Function countrecords() As Integer
Dim count As Integer
Dim cell As Range
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If Not IsEmpty(cell.Value) Then
count = count + 1
End If
Next cell
countrecords = count
End Function
'<<=============


---
Regards,
Norman



"Panagiotis Marantos" wrote
in message ...
can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default counting records

The error is with "Is Not Null"

try

If cell.Value < "" Then

Duncan


Panagiotis Marantos wrote:

can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
End Function


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default counting records

Panagiotis,
The keyword "Is" is used with Objects.
Dim WB As Workbook
On Error Resume Next
Set WB=Workbooks.Open(PathToFile)
If Not WB Is Nothing Then.....

But cell.value is not an object.
Depending what you are test for:
cell.value<0 or Not (cell.value=0)
cell.value<""
cell.value<Empty

NickHK

"Panagiotis Marantos" wrote
in message ...
can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
End Function



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default counting records

or......


Function countrecords() As Integer
Dim count As Integer
count = 0


For Each cell In Worksheets("sheet1").Range("A1:A500")
If cell.Value < isblank = True Then
count = count + 1
End If
Next cell
countrecords = count
MsgBox count
End Function






Norman Jones wrote:

Hi Panagiotis,

Try:

'=============
Public Function countrecords() As Integer
Dim count As Integer
Dim cell As Range
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If Not IsEmpty(cell.Value) Then
count = count + 1
End If
Next cell
countrecords = count
End Function
'<<=============


---
Regards,
Norman



"Panagiotis Marantos" wrote
in message ...
can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
End Function




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default counting records

Hi Panagiotis,

However, why not simply:

countrecords = Application.CountA(Range("A1:A500"))


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Panagiotis,

Try:

'=============
Public Function countrecords() As Integer
Dim count As Integer
Dim cell As Range
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If Not IsEmpty(cell.Value) Then
count = count + 1
End If
Next cell
countrecords = count
End Function
'<<=============


---
Regards,
Norman



"Panagiotis Marantos" wrote
in message ...
can somebody provide me with an answer as to why the following function
returns an error on the if line?

the error message is "object required"

Function countrecords() as integer
Dim count As Integer
count = 0

For Each cell In Worksheets("Saved Records").Range("A1:A500")
If cell.Value Is Not Null Then
count = count + 1
End If
Next cell
countrecords = count
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
Counting Records Between Two Dates Stevo Excel Worksheet Functions 7 July 29th 08 03:03 PM
Counting records f(x) two columns jkl Excel Discussion (Misc queries) 6 May 8th 07 05:39 PM
counting records [email protected] Excel Worksheet Functions 8 September 14th 06 09:38 PM
Counting unique records yhtak Excel Worksheet Functions 6 June 16th 06 02:34 PM
Counting records Slim Jim Excel Programming 1 January 12th 05 07:27 PM


All times are GMT +1. The time now is 10:47 PM.

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"