+ Reply to Thread
Results 1 to 8 of 8

Copy cells from a table to another table with conditions.

  1. #1
    Registered User
    Join Date
    01-22-2023
    Location
    Monterrey
    MS-Off Ver
    Office 365
    Posts
    5

    Lightbulb Copy cells from a table to another table with conditions.

    Hello everyone.

    I am trying to build an Excel script that basically follows the next steps:

    1. Look for the last row added to the table.
    2. Search for questions that have been answered as "Yes".
    3. If it founds a "Yes" value, it must copy the cell right next to it to another table, which is the answer given by the user. And also the name, nationality and age.

    Original Table (picture 1):

    Table 1.jpg

    Expected Table Result (picture 2):

    Table 2.png

    Here is the Excel file.
    Survey Trial (1).xlsx

    I will be very attentive to your answers. Thank you in advance.
    Last edited by AlexisUANL; 01-22-2023 at 11:55 PM. Reason: URGENT!

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,911

    Re: Copy cells from a table to another table with conditions.

    Here is one way that will hopefully do what you need and be easy enough to understand so you can adapt it to your workbook.
    Please Login or Register  to view this content.
    BSB

  3. #3
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2021
    Posts
    979

    Re: Copy cells from a table to another table with conditions.

    try

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-22-2023
    Location
    Monterrey
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Copy cells from a table to another table with conditions.

    Hello, would it be possible to transfer this to TypeScript language?, i am using Excel Online and does not support Macros.

  5. #5
    Registered User
    Join Date
    01-22-2023
    Location
    Monterrey
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Copy cells from a table to another table with conditions.

    Hello, thanks for the answer. I am using Excel Online and it does not support Macros. What I am trying to do is to create an Script and then activates it automatically with Power Automate every time a new response is received.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,911

    Re: Copy cells from a table to another table with conditions.

    Quote Originally Posted by AlexisUANL View Post
    What I am trying to do is to create an Script and then activates it automatically with Power Automate every time a new response is received.
    Quite an important piece of information to omit from the original request. A) because if you'd included it you could have attracted someone that could help and B) because it would have saved those that have looked and provided solutions so far from spending time doing that for no reason.

    I'm afraid I cannot help with the scripting for Power Automate as I don't have access to it.

    Good luck with the project.

    BSB

  7. #7
    Registered User
    Join Date
    01-22-2023
    Location
    Monterrey
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Copy cells from a table to another table with conditions.

    Thanks for the answer and the time. I am just struggling in making the Script, your code in VBA really help me a lot so far, but I am just looking how to do the same thing but with TypeScript language.

    This all because it is an Excel file located in One drive and I can only use Scripts, not macros

  8. #8
    Registered User
    Join Date
    01-24-2023
    Location
    Los Angeles
    MS-Off Ver
    Office 365
    Posts
    1

    Re: Copy cells from a table to another table with conditions.

    You can try the script below. I show that it is working with the file you provided:

    function main(workbook: ExcelScript.Workbook) {
    let inputTbl = workbook.getTable("Table1")
    let outputTbl = workbook.getTable("Table3")

    let nameCol = inputTbl.getColumnByName("Name").getRangeBetweenHeaderAndTotal().getValues() as string[][]
    let nationCol = inputTbl.getColumnByName("Write your nacionality.").getRangeBetweenHeaderAndTotal().getValues() as string[][]
    let cityCol = inputTbl.getColumnByName("Choose you city.").getRangeBetweenHeaderAndTotal().getValues() as string[][]
    let ageCol = inputTbl.getColumnByName("Write your age.").getRangeBetweenHeaderAndTotal().getValues() as string[][]

    let inputVals = inputTbl.getRangeBetweenHeaderAndTotal().getValues() as string[][]

    let inputRowCount = inputTbl.getRangeBetweenHeaderAndTotal().getRowCount()
    let inputColCount = inputTbl.getRangeBetweenHeaderAndTotal().getColumnCount()
    let tempArr: string[][] = []

    for (let i = 0; i < inputRowCount; i++) {
    for (let j = 0; j < inputColCount; j++) {
    if (inputVals[i][j] === "Yes") {
    let finding = inputVals[i][j + 1]
    let temp: string[] = [nameCol[i][0], finding, nationCol[i][0], cityCol[i][0], ageCol[i][0]]
    tempArr.push(temp)
    }
    }
    }

    outputTbl.addRows(-1,tempArr)

    }
    Last edited by b-gonzalez; 01-25-2023 at 10:54 PM.

+ 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] Need formula to count table range depending on conditions in selected table columns
    By jj2105 in forum Excel Formulas & Functions
    Replies: 29
    Last Post: 05-27-2022, 04:49 AM
  2. Macro to fill 1st table with info from 2nd table. 2nd table search with 2 conditions
    By Ribeiro.JD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-17-2016, 02:03 PM
  3. [SOLVED] copy dynamic data from one table to another one with 2 conditions
    By sa4a in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2014, 04:41 PM
  4. Macro to copy a table and paste in another table (based on certain conditions)
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-22-2013, 01:14 PM
  5. Merging Table Cells with Text under Certain Conditions
    By verdecove in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-31-2009, 08:08 PM
  6. Moving data from a pivot table to another table based on conditions
    By MarinaDBrown in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2009, 12:11 PM
  7. [SOLVED] sum cells in table using column and row conditions
    By NEIL@NEIL1975.PLUS.COM in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-06-2006, 03:10 AM

Tags for this Thread

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