Forum Discussion

Dan1ExcelUser's avatar
Dan1ExcelUser
Copper Contributor
Feb 05, 2025
Solved

How to fill a range of Sheet A with data from Sheet B by repeating this action for each value

Hi, I have two sheets A & B. Sheet A has a table where A1:H1 is the header. The range C2:C9 of this table is blank but there is data in the ranges A2:B9 and D2:H9. Sheet B has data in the range A...
  • SergeiBaklan's avatar
    Feb 10, 2025

    As variant

    function main(workbook: ExcelScript.Workbook) {
    
        const data = workbook.getWorksheet("SheetB")
            .getUsedRange().getValues().slice(1)
        const range = workbook.getWorksheet("SheetA")
            .getRange("A2:H10")
    
        let i = 0
        for (let item of data) {
            let next = range.getOffsetRange(9 * i, 0)
            i > 0 ? next.copyFrom(range) : ''
            next.getColumn(2).setValues(item[0])
            i += 1
        }
    }
    

Resources