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
Solved

Why does attempted match on a loop provide incorrect evaluation

Posted on 2014-03-04
4
99 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 50

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

828 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