VBA help - Count number of found results in a list

ScatmanKyle

Board Regular
Joined
Oct 26, 2015
Messages
65
Office Version
  1. 365
Platform
  1. Windows
I have a list of phone numbers in the sheet "Data Load", column C starting from the 3rd row. I'm trying to go down one at a time searching for those numbers in the "Lookup" tab to find how many numbers have not yet been entered into the "Lookup" tab. I put in two fake numbers into the list as a test, but my code is returning 0 as the final result for ErrCount. What am I doing wrong?


Code:
Sub NewNum()


Dim TempNum As String
Dim ErrCount As Double
Dim RowCount As Double


Set FindRange = Worksheets("Lookup").Range("A:A").Find(TempNum, , xlValues, xlWhole, xlByRows)


RowCount = 0


Sheets("Data Load").Select
Cells(3, 3).Select


Do Until IsEmpty(Cells(3 + RowCount, 3))


TempNum = ActiveCell.Offset(RowCount, 0).Value


If FindRange Is Nothing Then
    ErrCount = ErrCount + 1
Else
    ErrCount = ErrCount
End If


RowCount = RowCount + 1


Loop


End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This line needs to go inside the loop
Code:
Set FindRange = Worksheets("Lookup").Range("A:A").Find(TempNum, , xlValues, xlWhole, xlByRows)
Otherwise you are using it once & on that occasion its looking for a blank cell
 
Upvote 0
This line needs to go inside the loop
Code:
Set FindRange = Worksheets("Lookup").Range("A:A").Find(TempNum, , xlValues, xlWhole, xlByRows)
Otherwise you are using it once & on that occasion its looking for a blank cell

It worked! Could you explain it in further detail? It's my first time using the find function and using set.
 
Upvote 0
In your code, when you use that line "TempNum" does not have a value, so the Find will find the first blank cell, and as it was outside the loop it never runs again so you're loop was basically doing nothing.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top