Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Excel VBA "Object or With Block variable not set"

Posted on 2010-01-10
12
Medium Priority
?
261 Views
Last Modified: 2013-11-25

Hi there,  I can't figure out why my code stops on the second line of code (tbldata2VisCount) and not on the first? I hover over tbldataVisCount and it shows the correct count of filtered items but when I hover over tbldata2VisCount, the result = Emply

 Dim tbldataVisCount As Variant
 Dim tbldata2VisCount As Variant


 tbldataVisCount = Sheet4.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
 tbldata2VisCount = Sheet2.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1    ' this line keeps breaking
            dblCount = tbldataVisCount + tbldata2VisCount

Any thoughts?
0
Comment
Question by:Calvin LeBlanc
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 13

Expert Comment

by:ioane
ID: 26280326
Make sure you have a Sheet2 in your workbook.

Go to vba editor and check the names of the worksheets in the project tree.

Note, you want the Object instance name, not the Worksheet name.

Another way to write it that may work better is to use the Worksheet name:

 tbldataVisCount = Sheets("Sheet_Name").AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
0
 

Author Comment

by:Calvin LeBlanc
ID: 26280359
The workbook does have a Sheet2. I just tried using the sheet name and no go.
I tried to compare how the previous line is written and all seams to be fine.
0
 

Author Comment

by:Calvin LeBlanc
ID: 26280368
I"m basically wanting to count the number of result rows  in a "Filtered" table in two separate tables (tbl1data and tbl2data) and then add those two results to be used as a reference.  
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 50

Expert Comment

by:Dave Brett
ID: 26280433
Can you pls post your file

Cheers
Dave
0
 

Author Comment

by:Calvin LeBlanc
ID: 26280530
Dave, in attempting to sanitize the raw data in the workbook I restarted Excel and it seams to be working fine now. I'll test it a little more and post a status tomorrow afternoon. thanks for the assist !!
0
 
LVL 13

Accepted Solution

by:
ioane earned 1000 total points
ID: 26280561
Are you using AutoFilter in both tables?

See what you get when you add this:

Debug.print "Sheet4 AutoFilter is: " & iif(Sheet4.AutoFilterMode,"on","off")
 tbldataVisCount = Sheet4.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
Debug.print "Sheet2 AutoFilter is: " & iif(Sheet2.AutoFilterMode,"on","off")
 tbldata2VisCount = Sheet2.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1    ' this line keeps breaking
0
 

Author Comment

by:Calvin LeBlanc
ID: 26280605
Thanks for the post Tramtrak. Your solution seams to work too. I'll do more testing and post / divy up points tomorrow evening.

Thanks to you both for the assistance.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 26280612
If the file is working now then we haven't solved anything - so you delete your question and get your points refunded. :)

Cheers

Dave
0
 

Author Comment

by:Calvin LeBlanc
ID: 26280631
As an FYI, these lines of code seam to work fine on a data set of 20 records (in both tables) but breaks with a data set of 250,000 records in each of the tables.
still testing.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 26281289
Have you tried defining all your counter variables as Long?
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 1000 total points
ID: 26281295
Also if you are using tables in excel 2007 you really want the autofilter property of the listobject, not the worksheet.
Regards
Rory
0
 

Author Closing Comment

by:Calvin LeBlanc
ID: 31675920
Both solutions helped me better understand how to troubleshoot and resolve the issue.
Thanks to the both of you for the assistance.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question