Solved

Why does attempted match on a loop provide incorrect evaluation

Posted on 2014-03-04
4
96 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
4 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 275 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yikes...thanks for the solution and pointers
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now