Solved

Why does attempted match on a loop provide incorrect evaluation

Posted on 2014-03-04
4
107 Views
Last Modified: 2014-03-07
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
Comment
Question by:upobDaPlaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 275 total points
ID: 39905616
Hi,

you have 2 diferent variables

strProd  which has a value and

strproduct which is empty

Regards
0
 
LVL 22

Assisted Solution

by:Flyster
Flyster earned 113 total points
ID: 39905622
In addition to the above statement, your data tab list "Orange" and name range lists "Oranges"!

Flyster
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 112 total points
ID: 39906827
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
 

Author Closing Comment

by:upobDaPlaya
ID: 39914091
Yikes...thanks for the solution and pointers
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

707 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