google-apps-scriptgoogle-sheetsmacro-recorder

Macro Action: How to select a specific column or a specific range?


I want to create a macro in Google Sheets where part of the macro involves Selecting Column E, or selecting rows 2-1000. How can I do this?


Solution

  • select cell A2 and use:

    Selecting Column E

    function Macro1() {
      var spreadsheet = SpreadsheetApp.getActive();
      var sheet = spreadsheet.getActiveSheet();
      sheet.getRange(1, spreadsheet.getCurrentCell().getColumn() + 4, sheet.getMaxRows(), 1).activate();
    };
    

    selecting rows 2-1000

    function Macro2() {
      var spreadsheet = SpreadsheetApp.getActive();
      var sheet = spreadsheet.getActiveSheet();
      sheet.getRange(spreadsheet.getCurrentCell().getRow(), 1, 1, sheet.getMaxColumns()).activate();
      var currentCell = spreadsheet.getCurrentCell();
      spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
      currentCell.activateAsCurrentCell();
    };