+ Reply to Thread
Results 1 to 11 of 11

VBA Code to select each item in turn from a validation list and then run some other code

  1. #1
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    VBA Code to select each item in turn from a validation list and then run some other code

    Hi There,

    I have worksheet that uses a validation list as the source for various lookup functions, the end result is a dynamic report, I now intended to email this out automatically, I already have the code to create an email and attach the data in the body. However as the data is sensitive I need the data to be emailed to one person, per entry in the validation list - again all this has been coded correctly, in that when I manually select an entry the appropriate data is refreshed and an email generated with the correct recipient.

    Unfortunately i'm having a little mental block on how to go each item within the validation list, as there are currently 400 entries (set to grow), its quite a laborious process (albeit even now still faster than the previous method used).

    For reference purposes the validation list exists in a sheet named "STATEMENT" and CELL D2

    any help would be greatly received, thank you.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Something along the lines of

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Thank you Bernie,

    I must be doing something wrong as it's not quite working as intended, i've attached a sample sheet and i'm using the code:

    Please Login or Register  to view this content.
    just so that I could see (I hoped) the entries in the drop down validation cycle through, but I seem to be getting other weird entries too.

    Any Ideas?
    Attached Files Attached Files
    Last edited by Kramxel; 08-21-2014 at 11:08 AM. Reason: removed personal identifying infomation.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Book1 for upload.xlsm

    I re-did your named range, to be dynamic, so that as your list changes it will pick up all the values. Just don't put anything else into column A other than Agent names, and don't skip cells.
    Last edited by Bernie Deitrick; 08-21-2014 at 11:17 AM.

  5. #5
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Make sure you are putting the code in the right spot:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Hi Bernie,

    I'm still getting the erroneous entries i'm afraid, even after implementing these changes, I should point out that the agent names on my sheet are generated by looking at another sheet via

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Of course that matters....

    Change the definition of the named range Agents to

    =OFFSET(Overview!$A$5,0,0,COUNTA(Overview!$A:$A),1)

    or this, if you have a header over the list:

    =OFFSET(Overview!$A$5,0,0,COUNTA(Overview!$A:$A)-1,1)

    Assuming that the first name is in A5, and there are no skipped cells below - and assuming that there is nothing else you are not including, that should work.

  8. #8
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Hi Bernie,

    Thanks for your perseverance, I Have a header in cells A1:A2 (merged) first cell that has data is A3, and no skipped cells, I have therefore changed the definition to =OFFSET(Overview!$A$3,0,0,COUNTA(Overview!$A:$A)-1,1), bit get a run time error 1004 when stepping through at the point: Worksheets("Statement").Range("D2").Value = r.Value

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Sorry - forgot that the code was looking for the named range on the first sheet.

    Here you go, all fixed....

    Book1 for upload 2.xlsm

  10. #10
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    You sir are an official Legend!

    Thank you so much for your time and for helping me with this.

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,274

    Re: VBA Code to select each item in turn from a validation list and then run some other co

    Glad you like it!

+ 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. macro to select each item in data validation list
    By Olivia Wong in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-30-2013, 01:59 PM
  2. Macro to select an item from a data validation list
    By blindedbythepj in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-12-2012, 03:53 PM
  3. Replies: 1
    Last Post: 06-11-2012, 04:43 AM
  4. select mo/yr w/data validation list, insert celll entry into vba file reference code
    By ShannonHowell in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-10-2011, 04:07 AM
  5. Macro to select an item in a Validation List
    By emwhite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2010, 10:41 AM

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