+ Reply to Thread
Results 1 to 7 of 7

VBA code to populate a formula based on a table ( ID // Name)

  1. #1
    Registered User
    Join Date
    07-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2007
    Posts
    10

    VBA code to populate a formula based on a table ( ID // Name)

    Hello everyone,

    I've been trying to find a way to write a formula in vba but I only see stuff on how to insert a fixed formula,
    I'm trying to have a dynamically written formula by VBA


    The code would have to repeat a section of the formula [ ,IF(--NOT(ISERROR(SEARCH("for each project ID",H2))),"and each name", ]

    one after the other untill all projects are accounted for


    there may be up to a bunch of projects at a time but they will change often so that's why it needs to adjust to that.


    the first two arguments of the formula are

    =IF(A2=0,"",IF(--NOT(ISERROR(SEARCH("EXTRA",J2))),"EXTRA",

    followed by
    Something like

    IF(--NOT(ISERROR(SEARCH("first in list",H2))),"name1",IF(--NOT(ISERROR(SEARCH("Second in list",H2))),"name2",IF(--NOT(ISERROR(SEARCH("third in list",H2))),"name3",


    and so on until all projects are mentioned.


    with the final comma "false answer" being [ ,"Regular" ] if no project ID was found


    then to paste that in Column R of Sheet "LIVE ALL" (from R2 all the way down for each row of data on this sheet)


    The projects are written on a sheet called "Projects"

    Column A has an Sorting order number to help sort put the projects in order not to get false positives for incomplete matches.
    Column B has the project IDs
    Column C has the project names


    How would you approach this with VBA ?


    I have uploaded a sample Workbook you may download




    Thank you for your help and any guidance.
    Attached Files Attached Files
    Last edited by speedyacct; 09-22-2014 at 05:20 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA code to populate a formula based on a table ( ID // Name)

    I don't understand why you have gone into so much detail if all you want is a macro to insert your formula into column R.

    Am I missing something?

    Please Login or Register  to view this content.
    Have you thought that as your file gets bigger the calculation will slow down and also that your file might grow too big.

    You could use a sheet specific macro to insert the formula whenever a change is made,

    One the formula is inserted and calculated, the macro could copy paste the value.

    So column R would contain the right data but no formula.

    Would that work for you?

    If you would like something like that, then please advuse what sheet and cell update will trigger the creation of a formula in column R.

  3. #3
    Registered User
    Join Date
    07-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: VBA code to populate a formula based on a table ( ID // Name)

    the idea is to make it user friendly so the users can add and remove projects from the project table and the formula would adjust to it every time a macro is run to identify projects


    as far as DATA growing I am not concerned as i know it is working correctly with barely any delay to calculate I am already using this formula on my master sheet (20K+ Rows) but I write it myself and I am trying to have VBA do it so Other users can manipulate the projects and I wont have to write the formula for it each time projects change
    Last edited by speedyacct; 09-22-2014 at 04:29 PM.

  4. #4
    Registered User
    Join Date
    07-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: VBA code to populate a formula based on a table ( ID // Name)

    Let me know if you have any questions.
    Last edited by speedyacct; 09-22-2014 at 04:29 PM.

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA code to populate a formula based on a table ( ID // Name)

    Ok

    paste this formula into R2 and fill down:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: VBA code to populate a formula based on a table ( ID // Name)

    WOW that's a beautiful approach and i wont even need VBA

    Althought, that has a nested search for the word "project"

    Would it be possible to have this formula work without looking for a project name containing "project"

    all projects are differently named and some even have commas in them

    can this formula be adapted to pickup any strings written in column B of projects WITHOUT HAVING AN EMBEDDED search for the word "PROJECT" in the projects ?
    Last edited by speedyacct; 10-08-2014 at 12:09 PM.

  7. #7
    Registered User
    Join Date
    07-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2007
    Posts
    10

    Re: VBA code to populate a formula based on a table ( ID // Name)

    I got it .. Thanks for everyone's help


    this will do the matching and is way faster than VBA code !

    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] How to populate a table based on the searched values in a pivoted table
    By Kausty88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-19-2012, 06:11 AM
  2. Code/Macro to populate table based on user input.
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-08-2011, 07:50 AM
  3. VBA code to populate a table
    By roheba in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-02-2010, 11:26 AM
  4. Formula to Populate table based on 3 input values
    By Senthilerp in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-18-2009, 01:19 AM
  5. Populate Table 1 based on values in Table 2
    By Alan1981 in forum Excel General
    Replies: 5
    Last Post: 10-22-2007, 04:34 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