• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 118
  • Last Modified:

Why does attempted match on a loop provide incorrect evaluation

Why does a an empty cell in a a named range = a non blank cell.  I am attempting to match cells in the data tab vs the named range and for some reason if the named range is blank it thinks it equals a cell from the data tab with a value of "orange" as an example.  I on purpose had my range in the named range exceed the cells where I have values in the event I later add to the named range..

Sub LoopData()

Dim intD As Integer
Dim intE As Integer
Dim lastrow As Integer
Dim lr As Range

Dim strProd As String
intD = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row

For d = 2 To intD
 strProd = Sheets("Data").Range("A" & d)
        For Each lr In Range("ItemFocus")
            If strproduct = lr.Value Then
                MsgBox (lr.Value)
            Else
            End If
         Next lr
 Next d
           


End Sub
ee-loop.xlsm
0
upobDaPlaya
Asked:
upobDaPlaya
3 Solutions
 
Rgonzo1971Commented:
Hi,

you have 2 diferent variables

strProd  which has a value and

strproduct which is empty

Regards
0
 
FlysterCommented:
In addition to the above statement, your data tab list "Orange" and name range lists "Oranges"!

Flyster
0
 
nutschCommented:
To avoid or at least minimize the issue of wrong variables used, write
Option Explicit

Open in new window

at the top of your modules, this will ensure that an error gets raised if you use an undefined variable (strproduct in this case).

Thomas
0
 
upobDaPlayaAuthor Commented:
Yikes...thanks for the solution and pointers
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now