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

Restrict next record to a specific column for a named range

If have a named range and want to loop thru a specific column of the named range is this possible.  Note my defuned name range spans from A1:C300.  I want to loop thru Column A and if it matches then take a value found in the same row from column B.  Am I just better off not trying to leverage off my Defined Name and instead set the range (Col A) from within the code ?

Dim MyRng as Range

For each MyRng in Range("Produce")
  If "Orange" = MyRng THEN
     msgBox = MyRng.Offset(0,1)
else
 end if
0
upobDaPlaya
Asked:
upobDaPlaya
2 Solutions
 
NorieCommented:
If Produce is your named range you can loop through column A like this.
For each MyRng in Range("Produce").Columns(1).Cells
    If MyRng.Value = "Orange" THEN
        MsgBox MyRng.Offset(0,1)
   End If
Next MyRng

Open in new window

0
 
aikimarkCommented:
are you trying to replicate a VLookup() function?
0
 
upobDaPlayaAuthor Commented:
aikimark..i am just trying to learn more about applying named ranges within VBA..
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