I'm currently creating a sheet for some weekly workouts and I wanted to create a randomize button, using macros, that takes an x amount of exercises from a list and assigns them to their respective place - this way the workouts wouldn't get repetitive over time.
I'm veeery new to VBA coding, so I basically searched on the internet for a code that worked and I found one, but I encountered a couple of issues:
And here is my sheet as well.
I'm veeery new to VBA coding, so I basically searched on the internet for a code that worked and I found one, but I encountered a couple of issues:
- I can get it to work for the first section (Legs&Glutes), but when I went to change the code for the "Abs" section I realized that I can't get the exercises to start on row 12 (instead they just replace the first exercises of the "Legs&Glutes" section).
- I don't know how to make the code automatically change when I add a row. For example, I currently have 9 exercises for the first section but I wanted the code to automatically update after adding a row to assign more exercises (so if I added another row between row 10 and 11, the code would update to assign 10 exercises instead of 9, but also in a way that changes the Abs code to start on row 13).
VBA Code:
Sub Legs_And_Glutes()
Dim NameColumn As Integer
Dim FirstNameRow As Integer
Dim NewColumn As Integer
Dim NumberOfNames As Integer
Dim lrow As Long
Dim StoredNames As String
Dim Counter As Integer
Dim Name As String
NameColumn = 8 'Change this if your names are not in column A
FirstNameRow = 2 'Change this if your first name does not start in row 2 (1 would be the column header)
NewColumn = 2 'Change this if you want to change the column of 10 names from column E to a different column
NumberOfNames = 9 '10 Names in new list
lrow = Cells(Rows.Count, NameColumn).End(xlUp).Row
Counter = 2
StoredNames = ""
Cells(1, NewColumn) = "Exercises"
Range(Cells(2, NewColumn), Cells(NumberOfNames + 1, NewColumn)).ClearContents
Do Until Cells(NumberOfNames + 1, NewColumn) <> ""
Name = WorksheetFunction.Index(Range(Cells(FirstNameRow, NameColumn), Cells(lrow, NameColumn)), WorksheetFunction.RandBetween(1, lrow - FirstNameRow + 1))
If InStr(StoredNames, Name) = 0 Then
StoredNames = StoredNames & " " & Name
Cells(Counter, NewColumn) = Name
Counter = Counter + 1
End If
Loop
End Sub
And here is my sheet as well.
workout2 (version 1).xlsb | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
B | C | D | E | F | G | H | I | |||
1 | Exercises | Sets | Reps | Notes | Legs/Glutes | Abs | ||||
2 | side leg lifts | 10 | each leg | 2kgs | bulgarian split squat | bicycle crunches | ||||
3 | kneeling squats | 10 | x1 | 10 sec hold | donkey kicks | c curls | ||||
4 | donkey kicks pulse | 10 | each leg | donkey kicks pulse | crunches | |||||
5 | squats pulses w/leg raise | 10 | x1 | fire hydrants | heel touches | |||||
6 | stand up side kicks | 10 | x1 | fire hydrants kicks | leg raises | |||||
7 | bulgarian split squat | 10 | each leg | pulse 3 times | fire hydrants pulses | plank | ||||
8 | fire hydrants pulses | 10 | each leg | frog bridge pulses | plank side dips | |||||
9 | fire hydrants kicks | 10 | each leg | frog pump | reverse bicycle peddles | |||||
10 | side box leg lifts | 10 | each leg | hip thrusts/bridges | reverse crunches | |||||
11 | abs | kneeling squats | russian twists | |||||||
12 | plank | 10 | x1 | lunges | scissor extensions | |||||
13 | table top leg extensions | 10 | each leg | side box leg lifts | table top leg extensions | |||||
14 | reverse crunches | 10 | x1 | side kicks | ||||||
15 | bycicle kicks | 10 | each leg | side leg lifts | ||||||
16 | russian twists | 10 | x1 | side squats | ||||||
17 | leg raises | 10 | x1 | single leg RDL | ||||||
18 | squats | |||||||||
19 | squats pulses w/leg raise | |||||||||
20 | stand up side kicks | |||||||||
Monday (2) |