+ Reply to Thread
Results 1 to 8 of 8

Automatically populate a table with slected data based on criteria

  1. #1
    Registered User
    Join Date
    06-25-2013
    Location
    Leatherhead, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Automatically populate a table with slected data based on criteria

    Hi All

    This is my first post on the forum so apologies if I've posted this in the wrong area. I am an experienced excel user but haven't got round to learning VBA yet.

    I have a problem with some data handling at the moment.

    I have 6 tables of data that relate to different locations and shading types. I am trying to automate the spreadsheet to pull the data from one of these tables into a new table on a different worksheet based on selection criteria.

    For example, the first two tables refer to the SE and unshaded or intermittant shading respectively. In the main workbook I've setup an IF statement to give SE a value of 1, shaded a value of A and intermittant shading a value of B. I've then combined these two to give a reference of 1A or 1B. Based on this selection I would like the spreadsheet to pull in the information from the respective table into a new table in a different worksheet.

    I have named the ranges se_unshaded, se_intermittant etc and have tried to use the offset command to reproduce the information but to no avail.

    I'm not sure if this type of action requires a macro or whether there's a trick I'm missing.

    If anyone could point me in the right direction I would be eternally grateful.

    I've attached an extract of the spreadsheet to show what I'm trying to do.

    Cheers

    Rog

    Excel Forum Help.xlsx

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Automatically populate a table with slected data based on criteria

    Hi and welcome to the forum.

    A macro would be the simplest hence the change of extension in the attached to an .xlsm file.

    I couldn't see your IF test but I've added a drop down cell C2 where you can pick your table names. Just add any more table names to the Validation list.

    The macro is in the Sheet Change event of the Summary worksheet.

    Incidentally there's a mis-spelling of intermittent. ent not ant.
    Attached Files Attached Files
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-25-2013
    Location
    Leatherhead, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Automatically populate a table with slected data based on criteria

    Hi Richard

    That's great - thank you for your help

    Noticed the ent ant thing myself - been a long week and it's only Tuesday!

    If I attach the whole spreadsheet I'm working on would you be able to let me know if this would work in context?

    Sorry for being cheeky but I'm desperate to get this resolved.

    Cheers

    EDIT

    Managed to re-create the code in my man spreadsheet and all is working perfectly. Many thanks again for your help Richard

    Rog
    Last edited by smithrog; 06-25-2013 at 08:17 AM.

  4. #4
    Registered User
    Join Date
    06-25-2013
    Location
    Leatherhead, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Help modifying VBA to automate data selection

    Hi All

    I posted a problem with automatically selecting data earlier on this week. Had a wonderful reply that worked perfectly but have had some trouble adapting it to suit the final workbook. I have attached the full spreadsheet here and was wondering if anyone could recommend what changes are required to the code.

    Basically I have two if statements that return values based on selection in one worksheet. I have then combined them using the & statement to return a nemed range reference in a cell. This named range refers to data that I want to pull in from another worksheet. The current macro works but because I only posted an extract of the spreadshett ti only updates the values if you specifically select and change the cell. The original guy who solved this for me created a list validaiton so when you selected the name from the list the data updated. I need to monidfy this so that it updates automatically without the user having to slect the cell.

    I confess I have absolutely no idea about how to programme VBA so I am really stumped on this one. On another note, could anyone recommend a good book or two I could get so that I can start learning how to programme VBA? I'm very keen to learn.

    Thanks for your time

    Rog

    Admittance calcs update forum version.xlsm

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help modifying VBA to automate data selection

    Hi,

    Remove the existing Project Data Sheet Change macro and add the following Calculations Sheet Change macro

    Please Login or Register  to view this content.
    And create a new range name called "Selection2" for cell 'Project Data'!$E$6

  6. #6
    Registered User
    Join Date
    06-25-2013
    Location
    Leatherhead, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Automatically populate a table with slected data based on criteria

    Hi Richard

    Tried that but I now get the following message:

    Run-time error '1004':

    Method 'Range' of object'_Worksheet' failed

    It highlights this line in yellow

    If Not Intersect(Target, Range("Selection")) Is Nothing Then

    SOrry to be a pain and thank you so much for taking the time to help with this.

    Cheers

    Rog

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Automatically populate a table with slected data based on criteria

    Sorry,

    Forgot to mention you also need to change the definition of the Range Name 'Selection'

    This should now be defined as

    =Calculations!$P$29,Calculations!$P$33

    Since P29 or P33 on the Calculations sheet are the cells you change and on which B2 & B3 on Project Data are dependent.

  8. #8
    Registered User
    Join Date
    06-25-2013
    Location
    Leatherhead, England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Automatically populate a table with slected data based on criteria

    Richard you are a god in mortal clothes!

    Thank you so much for all your help on this.

    Many many thanks again

    Rog

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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