6

I'd like to copy and paste just values and format - not formula..

E.G (A1 is a dynamic text):

A1 = "test"

A2 = =A1

I'd like to use a script that when activated it copy A2 format and text (in this case would copy "test" - not "=a1") to A3 .

I tried with "formatOnly:true , contentsOnly:true" - but it keep copying formula.

function Threebrow() {  
   var sheet2 = SpreadsheetApp.getActive().getSheetByName('c');
  sheet2.getRange("a2").copyTo(sheet2.getRange(sheet2.getLastRow()+1,1,1,7), {formatOnly:true , contentsOnly:true});
}
Cooper
  • 48,630
  • 6
  • 20
  • 48
K. Bert
  • 124
  • 1
  • 1
  • 7

2 Answers2

16

Formulas are also counted as content in this context. The below function copies value and format of A2 to the lowest row in the first column.

function Threebrow() {  
  var sheet2 = SpreadsheetApp.getActive().getSheetByName('c');
  var sourceRange = sheet2.getRange("a2");
  var targetRange = sheet2.getRange(sheet2.getLastRow()+1,1,1,1);
  targetRange.setValues(sourceRange.getValues());
  sourceRange.copyTo(targetRange, {formatOnly:true})
}
Robin Gertenbach
  • 9,641
  • 2
  • 27
  • 36
0

More information requested: my function is not working on line n°9

function CopyFormatting() {
//Déclaration des variables
var SheetResponse = SpreadsheetApp.getActiveSheet(); //Sheet of forms response
var LastRow = SheetResponse.getLastRow(); //last row of sheet (n)
var RefRow = SheetResponse.getRange("3:3"); //Row n°3 considered as reference

//Copy formatting to last row from reference row
RefRow.copyTo(LastRow, {formatOnly: true});
}
Mohamed H
  • 159
  • 1
  • 4
  • 13