I have the challenge of aligning different subtypes of data from two separate sets next to each other. Currently, each set of data is in its own rows with 1500 columns. To intersperse them, I've been manually moving cells from below up in between the columns of the above dataset (and copying the title over both columns). However, I'm exploring using the "record" functionality to create a script/macro that can automate this process. The script needs to iterate over the entire sheet, which currently extends up until column BHT (but will grow as more columns are added). I'm struggling with looping through ranges based on letter values and instructing the computer to "repeat for the next column."
Here's the current script:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Insert copied cells from EC17:EC25 on selectedSheet to DW2:DW10 on selectedSheet.
selectedSheet.getRange("DW2:DW10").insert(ExcelScript.InsertShiftDirection.right);
selectedSheet.getRange("DW2:DW10").copyFrom(selectedSheet.getRange("EC17:EC25"));
// Paste to range DV1:DW1 on selectedSheet from range EC16 on selectedSheet
selectedSheet.getRange("EC16").moveTo(selectedSheet.getRange("DV1:DW1"));
// Paste to range DW1 on selectedSheet from range DV1 on selectedSheet
selectedSheet.getRange("DW1").copyFrom(selectedSheet.getRange("DV1"), ExcelScript.RangeCopyType.all, false, false);
// Set range DV1:DW1 on selectedSheet
selectedSheet.getRange("DV1:DW1").setValues([["YMEL1,1","YMEL1,2"]]);
// Clear ExcelScript.ClearApplyTo.contents from range EC17:EC25 on selectedSheet
selectedSheet.getRange("EC17:EC25").clear(ExcelScript.ClearApplyTo.contents);
}
I also came across code on this site that uses the following formula:
=IF(RIGHT($A2, 1) = "Z", CHAR(CODE(LEFT(A2, 1)) + 1), LEFT(A2, 1)) & CHAR(65 + MOD(CODE(RIGHT(A2, 1)) + 1 - 65, 26))
This formula updates letters, but I am unsure how to incorporate this letter iteration into loops that update both letters in the range for both the source and destination ranges...