Share via

Hello, I have this script below.

Anonymous
2024-07-22T14:41:29+00:00

Hello, I have this script below. Basically, what I want to happened is, every time I pressed one of those script buttons, I want to copy the contents of the rows and paste it to another sheet on the same workbook. I'm using Automate Office Scripts because I have this sheet online and shared to others.

This is the script and this is what the sheet looks like, I can't upload image that's why I just did this lol.

function main(workbook: ExcelScript.Workbook) {

    let sourceSheet = workbook.getWorksheet("Timer");
    let destSheet = workbook.getWorksheet("Logs");
    let sourceRange = sourceSheet.getRange("A2:C2");
    let sourceValues = sourceRange.getValues();
    let destRange = destSheet.getRange("A2:C2");
    destRange.clear();

    let destRangeValues = destSheet.getRange("A2:C2").setValues(sourceValues);
}

LOCATIONS: DEPARTURE: ARRIVAL:

LOCATION A: 5:30 AM 6:15 AM SCRIPT BUTTON 1

LOCATION B: 2:30 PM 3:15 PM SCRIPT BUTTON 2

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2024-07-28T02:20:55+00:00

    Hi,JermaineK

    I haven't heard back from you in a few days, so I'm wondering if you've referenced the script I used in my second reply. If you have any questions or problems, please feel free to communicate with us.

    I look forward to hearing from you and sharing more information.

    Zoro-MSFT | Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-07-25T02:21:14+00:00

    Hi,JermaineKL

    Thank you for your reply, as per your request, I have prepared a script for you which can get the “Timer” and “Logs” worksheets when you press the script button in the “Timer” worksheet.  Get the “Timer” and “Logs” sheet.If the Logs sheet does not exist, create it.Specify the row number to be copied (for example, row 2).Gets and copies the data for the specified row.Find the next blank row in the Logs worksheet and paste the data there.Clear the data in the specified row in the “Timer” worksheet.In this way, every time you press the Script button in the Timer worksheet, the data of the specific row will be safely stored in the Logs worksheet, and the corresponding row in the Timer worksheet will be cleared. “The corresponding row in the Timer sheet is cleared for new data entry.function main(workbook: ExcelScript.Workbook) {let sourceSheet: ExcelScript.Worksheet = workbook.getWorksheet("Timer");let destSheet: ExcelScript.Worksheet = workbook.getWorksheet("Logs");if (!destSheet) {destSheet = workbook.addWorksheet("Logs");}let rowToCopy: number = 2;let sourceRange: ExcelScript.Range = sourceSheet.getRange(A${rowToCopy}:C${rowToCopy});let sourceValues: (string | number | boolean)[][] = sourceRange.getValues();let usedRange = destSheet.getUsedRange();let nextEmptyRow: number = usedRange ? usedRange.getRowCount() + 1 : 1;let destRange: ExcelScript.Range = destSheet.getRange(A${nextEmptyRow}:C${nextEmptyRow});destRange.setValues(sourceValues);sourceRange.clear();}

    Best regards

    Zoro-MSFT | Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-07-23T14:38:54+00:00

    Hi,JermaineKL

    Welcome to the Microsoft Community.

    Thank you for sharing with us your experience and specific implementation of using automation scripts in Excel Online. We have tested the script you provided and confirmed that it works as expected, i.e. copying specific rows of data to another worksheet in the same workbook with the click of a button.  Image Your practice demonstrates a deep understanding and effective use of Excel functionality, which is important for improving productivity and fostering teamwork. We encourage you to continue to explore and share your experiences to help other users better utilize Excel.

    Please feel free to contact us if you have any questions about your future use or if you have further needs.

    Best regards

    Zoro-MSFT | Microsoft Community Support Specialist

    Good Day, Zoro!

    I still need to achieve something with this. I have another script button in Timer sheet which will clear the information/data in that particular row once it's pressed. However, I want to store that information first in "Logs" sheet before clearing/erasing the information/data in that particular row. Logs sheet is basically a information/data history that had been entered in Timer sheet.

    Thank you!

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-07-23T03:19:22+00:00

    Hi,JermaineKL

    Welcome to the Microsoft Community.

    Thank you for sharing with us your experience and specific implementation of using automation scripts in Excel Online. We have tested the script you provided and confirmed that it works as expected, i.e. copying specific rows of data to another worksheet in the same workbook with the click of a button.  Your practice demonstrates a deep understanding and effective use of Excel functionality, which is important for improving productivity and fostering teamwork. We encourage you to continue to explore and share your experiences to help other users better utilize Excel.

    Please feel free to contact us if you have any questions about your future use or if you have further needs.

    Best regards

    Zoro-MSFT | Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments