Button (or drawing) to copy specific text from bottom row to next blank row? Google sheets

azairvine

New Member
Joined
Nov 17, 2018
Messages
17
Hopefully I can describe this one succinctly. I would like a generic button that will copy the contents of specific cells in the bottom row of a sheet, and paste those values into the row below (first blank row).

I won't post the whole spreadsheet as it's a huge mess of formulas and whatnot.

d41UWGY.jpg


Upon triggering the "button" - cell data from col C, D, & E will be copied down to the blank line. Formulae will fill col A, & B - the other columns will be entered manually.

The idea is that I just completed a game, and I am going to play another game with the same settings. It would save me manually entering the same data over and over (or copy paste, etc).

My understanding is that I will need a script that will locate the contents of the last row and then copy col C, D, & E contents to the following row. I just have no idea how to script that.

Thanks in advance.
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Re: Button (or drawing) to copy specific text from bottom row to next blank row?

Hello,

something on the lines of

Code:
Sub COPY_LAST_ROW()
    MY_LAST_ROW = Range("A" & Rows.Count).End(xlUp).Row
    Range("A" & MY_LAST_ROW & ":E" & MY_LAST_ROW).Copy
    Range("A" & MY_LAST_ROW + 1).PasteSpecial (xlPasteAll)
    Application.CutCopyMode = False
End Sub
 
Last edited:
Upvote 0
Re: Button (or drawing) to copy specific text from bottom row to next blank row?

Thanks for your reply!

But oh crap, this is VBA isn't it? I forgot to mention that I use Googlesheets and so it needs to be javascript, which I have little to no idea about :(
 
Upvote 0
Re: Button (or drawing) to copy specific text from bottom row to next blank row?

Figured it out myself thanks to some existing code that I Googled and modified where necessary. Not bad considering I have no idea how to write in that language

function onEdit(e) {
if (e.range.getSheet().getSheetName() == 'Rumble' && e.range.getColumn() == 3) {
e.range.offset(0,-2).setValue(e.value.length>0 ? new Date() : '');//sets the current date to col A on any edit for a new game
}
}


function anotherGame () {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var last = sheet.getLastRow();

sheet.getRange(last+1, 1, 1, 1).setValue(new Date());//sets the current date to the first blank row for a new game

var gameCounter = sheet.getRange(last, 2, 1, 1).getValue();//gets value for game counter from the row above
var incrementGame = gameCounter + 1;//increments game counter by 1
sheet.getRange(last+1, 2, 1, 1).setValue(incrementGame);//sets the new game counter on the first blank row

var anotherGame1 = sheet.getRange(last, 3, 1, 3).getValues();//gets values for Region, Rank, & Deck from last game
sheet.getRange(last+1, 3, 1, 3).setValues(anotherGame1);//sets the new game Region, Rank & Deck the same as last game

var anotherGame2 = sheet.getRange(last, 7, 1, 1).getValue();//gets value for Opp from last game
sheet.getRange(last+1, 3, 1, 3).setValue(anotherGame2);//sets the new game Opp the same as last game
}


function diffGameCounter() {

var AUTOINC_COLUMN = 1;
var HEADER_ROW_COUNT = 1;

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
var rows = worksheet.getDataRange().getNumRows();
var vals = worksheet.getSheetValues(1, 1, rows, 2);

for (var row = HEADER_ROW_COUNT; row < vals.length; row++) {
try {
var id = vals[row][AUTOINC_COLUMN];
Logger.log(id);Logger.log((""+id).length ===0);
if ((""+id).length === 0) {
// Here the columns & rows are 1-indexed
sheet.getRange(row+1, AUTOINC_COLUMN+1).setValue(row);
}
} catch(ex) {
// Keep calm and carry on
}
}
}
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top