Copy / Paste into Next Available Cell in Column

11 views
Skip to first unread message

Tamara Dixon

unread,
May 9, 2023, 10:54:39 AM5/9/23
to Google Apps Script Community
The below should result in a list of hashtags being copied and pasted to column B, and a date pasted to column A for each of the hashtags, within a particular tab. The "hashtag" script works perfectly every time.

The "date" script is a replica (with source and destination references updated), but it's only intermittently working; sometimes it pastes the values in the next available cell as intended, but other times it pastes them way down column A instead.

What am I missing please? I'm not overly familiar with Google scripts and have been adapting details found online for the steps needed, so I'm open to different codes if they'll work better to achieve the same result... but formulas exist in other columns that need to be taken into account (ie the entire row isn't blank where the data needs to go, only columns A and B are blank).

// Copy & Paste Selected Hashtags to "Hashtag Records" Tab
var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Hashtag Records'), true);
  spreadsheet.getRange('B1').activate();
  spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  spreadsheet.getCurrentCell().offset(1, 0).activate();
  spreadsheet.getRange('\'Hashtag Selector\'!K5:K50').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
// Copy & Paste Dates as Values within "Hashtag Records" Tab
var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Hashtag Records'), true);
  spreadsheet.getRange('A1').activate();
  spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  spreadsheet.getCurrentCell().offset(1, 0).activate();
  spreadsheet.getRange('\'Hashtag Selector\'!O5:O50').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);


Reply all
Reply to author
Forward
0 new messages