+ Reply to Thread
Results 1 to 9 of 9

Loop issues - Find value in range that fits value in defined name range

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Loop issues - Find value in range that fits value in defined name range

    I have a ton of data to filter and copy out to new workbooks based on a portfolio code.

    I am attempting to loop through "rng" which is the unique numbers from the data, and I am looking it up in "wsd" which is the raw data sheets colum E which holds each lines portfolio code.

    This is my first attempt at a loop with vba and I'm having an issue with looking up a range and referencing it against another range. The below code is giving me a runtime error 13 "Type Mismatch" message but I can't figure out why. I have a few ideas but none I can work out how to create a fix. Any suggestions as always welcomed

    Please Login or Register  to view this content.
    At the moment I am testing but when done K2:K3 becomes "portf" which is a defined name range of 200 odd lines in the G column of sheets "Stats"
    Last edited by Sc0tt1e; 10-31-2014 at 09:35 AM.

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Loop issues - Find value in range that fits value in defined name range

    Hi,

    try this approach of using ado to extract based on a sql statement.
    Attached Files Attached Files
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Loop issues - Find value in range that fits value in defined name range

    Hi,

    You cannot compare two range like this. You need to check cells wise. You can do something like below:


    Please Login or Register  to view this content.

    Regards,
    Paresh J
    Last edited by pareshj; 10-31-2014 at 10:12 AM.
    Click on "* Add Reputation" as a way to say thanks

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Loop issues - Find value in range that fits value in defined name range

    Paresh

    Just to confirm,

    I want row one of rng to run through every row of "wds" then once the end has been reached row 2 or "rng" will run through every row of "wds" and so on and so on until "rng" has been exhausted.

    Does the code you have provided loop in this order?

    By the way you have put
    Please Login or Register  to view this content.
    would one of them not need to be cell2?

  5. #5
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Loop issues - Find value in range that fits value in defined name range

    Yes, exactly it runs the same way as you said. And my apologies, it should be
    Please Login or Register  to view this content.
    Regards,
    Paresh J

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Loop issues - Find value in range that fits value in defined name range

    I'm trying to paste the values copied within the loop to no avail, any ideas of the correct syntax or method?

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Loop issues - Find value in range that fits value in defined name range

    What exactly you want to paste. Is it a range of cells or single cell?

    As your code has changed, you need to modify this part too.

    What you need to do is get the union of range of cells when your are in for loop and select that range for copy and the your further code will work.

    Regards,
    Paresh J

  8. #8
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Loop issues - Find value in range that fits value in defined name range

    I want to run through "rng" one line at a time and have it run through all of "wsd", I want one book to be opened and whenever I have a match between "rng" value and a value in "wds" I want it to copy the line and paste it into wb2.

    When the loop has run through all of "wsd" I want the wb2 book to be closed and saved in the "spath" location with the name of the "rng".xlsx value that was being searched.

  9. #9
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Loop issues - Find value in range that fits value in defined name range

    Code as is stands

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula to determine if a number fits in a range
    By hwishman in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-03-2014, 06:06 PM
  2. Find most recent date within a defined range of dates
    By xltbob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-10-2012, 02:21 PM
  3. Loop through worksheets which are defined in a range of cells
    By OilMan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-23-2010, 02:37 AM
  4. help to create loop in a defined range
    By azegurb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2009, 03:24 AM
  5. Find names not in defined range
    By Chuck N in forum Excel General
    Replies: 1
    Last Post: 06-08-2007, 09:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1