Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2007, 06:24 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default WorksheetFunction.COUNTIF fails on the second pass

Hello,
has anyone encountered with the following problem?
I have a macro that counts non-empty cells in columns. It works on the first pass, but for all consecutive ones shows a "Type Mismatch" error. The code is below:

For i = 2 To numColumns
 With wb.Worksheets("Sheet1")
  Set r = .Range(.Cells(1, i), .Cells(numRows, i))
  .Cells(numRows+1, i) = WorksheetFunction.CountIf(r, ">0")
 End With
Next i

Thanks in advance.
 
Old April 24th, 2007, 02:46 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Flower,

Do any of your cells have textual data in?

This may not be actual text, it could be a space, or even just a "'".

Regards,
Rob

 
Old April 24th, 2007, 11:49 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Robzyc, thanks for your interest.
The columns contains integers and empty strings (""). I wrote a code that manually goes through each column and count non-empty cells (without using countif but looping through columns and then rows); however, it is too long for huge data.
 
Old April 25th, 2007, 02:45 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Hi Flower,
Well I dont know how much this one is helpfull for you but to check Non zero I use

 If Nz(rs!field1, "") <> "" then
   'do some thing
 End if

' to check value is null or not
 IsNull(rs!field1)

Regards

Ayaz






Similar Threads
Thread Thread Starter Forum Replies Last Post
Countif in VBA xbenx Excel VBA 9 November 5th, 2011 11:15 PM
What are the WorksheetFunction.Find arguments? BrianWren Excel VBA 3 October 24th, 2007 12:21 PM
COUNTIF Function can't reference other workbooks kuznickic Excel VBA 1 October 5th, 2007 04:35 AM
login fails... yasminnnnn ASP.NET 2.0 Basics 6 December 12th, 2006 03:49 PM
insert fails Mitch MySQL 3 June 3rd, 2006 11:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.