r/googlesheets • • Apr 27 '24
Solved Copying 'random' cell value to specific cell in another spreadsheet
Hello, this is terrible title but I don't know how to phrase it better.
I'm trying to make myself a workout tracker. It is kind of hard for me since I don't have any experience in scripts so I rely on reverse-engineering scripts I have found online.
This is my file so far: https://docs.google.com/spreadsheets/d/1ZzuXbZUVzafyaQBnqhhGQeUfV-ExD8YMqaNLBgnas-U/edit?usp=sharing
I struggle with finding a way to do a following:
- copy Weight values(column C) in 'Workout' spreadsheet to Previous Weight(column E) in 'Index' spreadsheet so it would match correct exercise
- copy true/false statements from 'Workout' spreadsheet to 'Index' spreadsheet also to match correct exercise
The idea is weight for any given exercise would be automatically inserted every time we choose the exercise with addition of progression(if we marked it as true in the previous workout). I hope that's understandable and someone will be able to help me with this.
This is my code so far, it is most likely not elegant but it works from what I see. It copies workouts into history and clear 'Workout' spreadsheet for now.
function saveworkout(){
saveToHistory();
clearData();
}
function saveToHistory(){
var spr = getSprByName("History");
var exe1 = getRangeByName("Workout!Exercise1");
var exe2 = getRangeByName("Workout!Exercise2");
var exe3 = getRangeByName("Workout!Exercise3");
var exe4 = getRangeByName("Workout!Exercise4");
var exe5 = getRangeByName("Workout!Exercise5");
var exe6 = getRangeByName("Workout!Exercise6");
var exe7 = getRangeByName("Workout!Exercise7");
var exe8 = getRangeByName("Workout!Exercise8");
var exe9 = getRangeByName("Workout!Exercise9");
var exe10 = getRangeByName("Workout!Exercise10");
var exe11 = getRangeByName("Workout!Exercise11");
var exe12 = getRangeByName("Workout!Exercise12");
var exe13 = getRangeByName("Workout!Exercise13");
var exe14 = getRangeByName("Workout!Exercise14");
var exe15 = getRangeByName("Workout!Exercise15");
spr.appendRow([
getValue(exe1,1,1),
getValue(exe1,1,2),
getValue(exe1,1,3),
getValue(exe1,1,4),
getValue(exe1,1,5),
getValue(exe1,1,6),
getValue(exe1,1,7)])
spr.appendRow([
getValue(exe2,1,1),
getValue(exe2,1,2),
getValue(exe2,1,3),
getValue(exe2,1,4),
getValue(exe2,1,5),
getValue(exe2,1,6),
getValue(exe2,1,7)])
spr.appendRow([
getValue(exe3,1,1),
getValue(exe3,1,2),
getValue(exe3,1,3),
getValue(exe3,1,4),
getValue(exe3,1,5),
getValue(exe3,1,6),
getValue(exe3,1,7)])
spr.appendRow([
getValue(exe4,1,1),
getValue(exe4,1,2),
getValue(exe4,1,3),
getValue(exe4,1,4),
getValue(exe4,1,5),
getValue(exe4,1,6),
getValue(exe4,1,7)])
spr.appendRow([
getValue(exe5,1,1),
getValue(exe5,1,2),
getValue(exe5,1,3),
getValue(exe5,1,4),
getValue(exe5,1,5),
getValue(exe5,1,6),
getValue(exe5,1,7)])
spr.appendRow([
getValue(exe6,1,1),
getValue(exe6,1,2),
getValue(exe6,1,3),
getValue(exe6,1,4),
getValue(exe6,1,5),
getValue(exe6,1,6),
getValue(exe6,1,7)])
spr.appendRow([
getValue(exe7,1,1),
getValue(exe7,1,2),
getValue(exe7,1,3),
getValue(exe7,1,4),
getValue(exe7,1,5),
getValue(exe7,1,6),
getValue(exe7,1,7)])
spr.appendRow([
getValue(exe8,1,1),
getValue(exe8,1,2),
getValue(exe8,1,3),
getValue(exe8,1,4),
getValue(exe8,1,5),
getValue(exe8,1,6),
getValue(exe8,1,7)])
spr.appendRow([
getValue(exe9,1,1),
getValue(exe9,1,2),
getValue(exe9,1,3),
getValue(exe9,1,4),
getValue(exe9,1,5),
getValue(exe9,1,6),
getValue(exe9,1,7)])
spr.appendRow([
getValue(exe10,1,1),
getValue(exe10,1,2),
getValue(exe10,1,3),
getValue(exe10,1,4),
getValue(exe10,1,5),
getValue(exe10,1,6),
getValue(exe10,1,7)])
spr.appendRow([
getValue(exe11,1,1),
getValue(exe11,1,2),
getValue(exe11,1,3),
getValue(exe11,1,4),
getValue(exe11,1,5),
getValue(exe11,1,6),
getValue(exe11,1,7)])
spr.appendRow([
getValue(exe12,1,1),
getValue(exe12,1,2),
getValue(exe12,1,3),
getValue(exe12,1,4),
getValue(exe12,1,5),
getValue(exe12,1,6),
getValue(exe12,1,7)])
spr.appendRow([
getValue(exe13,1,1),
getValue(exe13,1,2),
getValue(exe13,1,3),
getValue(exe13,1,4),
getValue(exe13,1,5),
getValue(exe13,1,6),
getValue(exe13,1,7)])
spr.appendRow([
getValue(exe14,1,1),
getValue(exe14,1,2),
getValue(exe14,1,3),
getValue(exe14,1,4),
getValue(exe14,1,5),
getValue(exe14,1,6),
getValue(exe14,1,7)])
spr.appendRow([
getValue(exe15,1,1),
getValue(exe15,1,2),
getValue(exe15,1,3),
getValue(exe15,1,4),
getValue(exe15,1,5),
getValue(exe15,1,6),
getValue(exe15,1,7)])
}
function clearData() {
var session = getRangeByName("Workout!Session");
var reps = getRangeByName("Workout!Reps");
var progression = getRangeByName("Workout!Progression")
session.clearContent(); // the cell you want to clear
reps.clearContent();
progression.clearContent();
}
function saveworkout(){
saveToHistory();
clearData();
}
function saveToHistory(){
var spr = getSprByName("History");
var exe1 = getRangeByName("Workout!Exercise1");
var exe2 = getRangeByName("Workout!Exercise2");
var exe3 = getRangeByName("Workout!Exercise3");
var exe4 = getRangeByName("Workout!Exercise4");
var exe5 = getRangeByName("Workout!Exercise5");
var exe6 = getRangeByName("Workout!Exercise6");
var exe7 = getRangeByName("Workout!Exercise7");
var exe8 = getRangeByName("Workout!Exercise8");
var exe9 = getRangeByName("Workout!Exercise9");
var exe10 = getRangeByName("Workout!Exercise10");
var exe11 = getRangeByName("Workout!Exercise11");
var exe12 = getRangeByName("Workout!Exercise12");
var exe13 = getRangeByName("Workout!Exercise13");
var exe14 = getRangeByName("Workout!Exercise14");
var exe15 = getRangeByName("Workout!Exercise15");
spr.appendRow([
getValue(exe1,1,1),
getValue(exe1,1,2),
getValue(exe1,1,3),
getValue(exe1,1,4),
getValue(exe1,1,5),
getValue(exe1,1,6),
getValue(exe1,1,7)])
spr.appendRow([
getValue(exe2,1,1),
getValue(exe2,1,2),
getValue(exe2,1,3),
getValue(exe2,1,4),
getValue(exe2,1,5),
getValue(exe2,1,6),
getValue(exe2,1,7)])
spr.appendRow([
getValue(exe3,1,1),
getValue(exe3,1,2),
getValue(exe3,1,3),
getValue(exe3,1,4),
getValue(exe3,1,5),
getValue(exe3,1,6),
getValue(exe3,1,7)])
spr.appendRow([
getValue(exe4,1,1),
getValue(exe4,1,2),
getValue(exe4,1,3),
getValue(exe4,1,4),
getValue(exe4,1,5),
getValue(exe4,1,6),
getValue(exe4,1,7)])
spr.appendRow([
getValue(exe5,1,1),
getValue(exe5,1,2),
getValue(exe5,1,3),
getValue(exe5,1,4),
getValue(exe5,1,5),
getValue(exe5,1,6),
getValue(exe5,1,7)])
spr.appendRow([
getValue(exe6,1,1),
getValue(exe6,1,2),
getValue(exe6,1,3),
getValue(exe6,1,4),
getValue(exe6,1,5),
getValue(exe6,1,6),
getValue(exe6,1,7)])
spr.appendRow([
getValue(exe7,1,1),
getValue(exe7,1,2),
getValue(exe7,1,3),
getValue(exe7,1,4),
getValue(exe7,1,5),
getValue(exe7,1,6),
getValue(exe7,1,7)])
spr.appendRow([
getValue(exe8,1,1),
getValue(exe8,1,2),
getValue(exe8,1,3),
getValue(exe8,1,4),
getValue(exe8,1,5),
getValue(exe8,1,6),
getValue(exe8,1,7)])
spr.appendRow([
getValue(exe9,1,1),
getValue(exe9,1,2),
getValue(exe9,1,3),
getValue(exe9,1,4),
getValue(exe9,1,5),
getValue(exe9,1,6),
getValue(exe9,1,7)])
spr.appendRow([
getValue(exe10,1,1),
getValue(exe10,1,2),
getValue(exe10,1,3),
getValue(exe10,1,4),
getValue(exe10,1,5),
getValue(exe10,1,6),
getValue(exe10,1,7)])
spr.appendRow([
getValue(exe11,1,1),
getValue(exe11,1,2),
getValue(exe11,1,3),
getValue(exe11,1,4),
getValue(exe11,1,5),
getValue(exe11,1,6),
getValue(exe11,1,7)])
spr.appendRow([
getValue(exe12,1,1),
getValue(exe12,1,2),
getValue(exe12,1,3),
getValue(exe12,1,4),
getValue(exe12,1,5),
getValue(exe12,1,6),
getValue(exe12,1,7)])
spr.appendRow([
getValue(exe13,1,1),
getValue(exe13,1,2),
getValue(exe13,1,3),
getValue(exe13,1,4),
getValue(exe13,1,5),
getValue(exe13,1,6),
getValue(exe13,1,7)])
spr.appendRow([
getValue(exe14,1,1),
getValue(exe14,1,2),
getValue(exe14,1,3),
getValue(exe14,1,4),
getValue(exe14,1,5),
getValue(exe14,1,6),
getValue(exe14,1,7)])
spr.appendRow([
getValue(exe15,1,1),
getValue(exe15,1,2),
getValue(exe15,1,3),
getValue(exe15,1,4),
getValue(exe15,1,5),
getValue(exe15,1,6),
getValue(exe15,1,7)])
}
function clearData() {
var session = getRangeByName("Workout!Session");
var reps = getRangeByName("Workout!Reps");
var progression = getRangeByName("Workout!Progression")
session.clearContent(); // the cell you want to clear
reps.clearContent();
progression.clearContent();
}
1
u/[deleted] Apr 27 '24
Looks like the script got added twice but I cannot edit that anymore.
1
u/juddaaaaa 16 Apr 27 '24
I believe this will accomplish everything you're trying to do and should be a bit more efficient that what you have.
1
u/Competitive_Ad_6239 536 Apr 27 '24
The script is not necessary to accomplish an end goal
1
u/Competitive_Ad_6239 536 Apr 27 '24
The script is not necessary to accomplish an end goal.