LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default problem with Rows.Count and comparing cells

I'm trying to make a simple program to take two columns of tags and
compare them to find any entries in the first column that aren't in
the second. I'm running into two problems that are giving me trouble.

The first is that the count function is counting all rows in Excel,
including the blank ones. I get an overflow error when I use integers
even though I only have about 900 records in each table. I can keep it
from crashing by changing the variables to a long. The value returned
is 65536, the maximum number of rows Excel supports. This shouldn't be
how the function works, and I'm not sure what I'm doing wrong with it.
With this huge value the program still crashes at the for loops when
the it runs out of memory. Is there a way to get the count function to
not count all those blank rows Excel throws in at the end?

Also, rather than use count, I just set the number of rows to
arbitrary numbers and tried running it. I have a problem when I try to
compare values in two cells. I get a "Run Time Error '1004':
Application-defined or object-defined error". This is my first attempt
at using at using VBA with excel, so if anyone can help me out I'd
apreciate it. Here's the code if it helps:

Dim sheet1_rows As Integer
Dim sheet2_rows As Integer
Dim counter As Integer
Dim add As Boolean
Sub compare()

sheet1_rows = Sheet1.Rows.count
sheet2_rows = Sheet2.Rows.count
count = 0

For i = 0 To sheet1_rows Step 1
add = True
For j = 0 To sheet2_rows Step 1
If Sheet1.Cells(i, 2).Value = Sheet2.Cells(j, 2).Value
Then
add = False
j = sheet2_rows
End If
Next j
If add Then
Sheet3.Cells(count, 1) = Sheet1.Cells(i, 2)
count = count + 1
End If
Next i
End Sub
 
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 if comparing 2 cells chris Excel Worksheet Functions 1 November 4th 08 04:53 PM
Lookup/count blank cells problem Tom Watt Excel Discussion (Misc queries) 9 September 12th 06 10:44 PM
How do I count nonblank cells in rows within Excel? JoJo New Users to Excel 1 February 14th 06 04:11 PM
Comparing two cells in a colum with 2000 rows thomas1075 Excel Discussion (Misc queries) 3 June 7th 05 08:12 AM
Problem with UsedRange.Rows.Count alainB[_15_] Excel Programming 4 April 29th 04 10:29 PM


All times are GMT +1. The time now is 08:16 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"