1

In Google Sheets, cell A1 contains the number of times the letter "A" should be repeated in cell B1

i.e.

If A1=3 then B1="A A A"

My rough script is:

for(var arow=0; arow<4; arow++) {
  var numberofo = actsheet.getRange(arow+1,1).getValue();
     for(i=0; i<=numberofo;i++) {
         var test = actsheet.getRange(i+1,2).setValue("o");
     };
 }

Sorry the code looks rough. Haven't coded for the last 7 years.

0

2 Answers 2

1

Is this a scripting challenge for yourself? Or are you actually trying to solve a real-world problem. If the latter, you don't need script, just a formula:

=REPT("A",A1)

0
0

If your intent is to return A A A as opposed to AAA

=JOIN("", REPT("A", A1)) 

or

=TRIM(REPT("A ", A1)) 

JOINREPTTRIM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.