Public Sub correctBugs() Dim i As Long Dim tmpRow1 As Long, tmpRow2 As Long, tmpColumn1 As Long, tmpColumn2 As Long Dim mNoOfRowsPerDay As Integer Dim mNoOfTrainingTypes As Integer Dim mNoOfDays As Long Dim mNoOfWeeks As Long Dim mNoOfMonths As Long Dim mDayStartRow As Long, mDayStartColumn As Long Dim mDayNoOfRows, mDayNoOfColumns As Long Dim mWeekStartRow As Long, mWeekStartColumn As Long Dim mWeekNoOfRows, mWeekNoOfColumns As Long Dim mMonthStartRow As Long, mMonthStartColumn As Long Dim mMonthNoOfRows, mMonthNoOfColumns As Long Dim mStartDate As Date, mEndDate As Date Dim mStartWeek As Long, mEndWeek As Long Dim mStartMonth As Long, mEndMonth As Long Dim mShowHeartRate As Boolean, mShowOTechnic As Boolean, mShowLegPlaces As Boolean Dim chartObjectIndex As Integer mStartDate = CDate(shtSetup.Cells(6, 5).Value) mEndDate = CDate(shtSetup.Cells(7, 5).Value) ' training types mNoOfTrainingTypes = 0 For i = 0 To 9 If shtSetup.Cells(11 + i, 3).Value <> "" Then mNoOfTrainingTypes = mNoOfTrainingTypes + 1 End If Next mStartWeek = serialWeek(mStartDate) mEndWeek = serialWeek(mEndDate) mStartMonth = serialMonth(mStartDate) mEndMonth = serialMonth(mEndDate) mShowHeartRate = (shtSetup.Cells(24, 5).Value = "Ja") mShowOTechnic = (shtSetup.Cells(25, 5).Value = "Ja") mShowLegPlaces = (shtSetup.Cells(26, 5).Value = "Ja") mNoOfRowsPerDay = 4 mNoOfDays = CLng(mEndDate) - CLng(mStartDate) + 1 mNoOfWeeks = mEndWeek - mStartWeek + 1 mNoOfMonths = mEndMonth - mStartMonth + 1 mDayStartRow = 5 mDayStartColumn = 2 mDayNoOfRows = mNoOfDays * mNoOfRowsPerDay mDayNoOfColumns = 17 + IIf(mShowHeartRate, 4, 0) + IIf(mShowOTechnic, 4, 0) + IIf(mShowLegPlaces, 4, 0) mWeekStartRow = 4 mWeekStartColumn = 2 mWeekNoOfRows = (mEndWeek - mStartWeek + 1) * 2 mWeekNoOfColumns = 15 + mNoOfTrainingTypes * 2 + IIf(mShowOTechnic, 4, 0) + IIf(mShowLegPlaces, 4, 0) mMonthStartRow = 4 mMonthStartColumn = 2 mMonthNoOfRows = (mEndMonth - mStartMonth + 1) * 2 mMonthNoOfColumns = 15 + mNoOfTrainingTypes * 2 + IIf(mShowOTechnic, 4, 0) + IIf(mShowLegPlaces, 4, 0) ' DAY GRAPH SHEET shtDayGraphs.Activate tmpRow1 = mDayStartRow tmpRow2 = mDayStartRow + mNoOfRowsPerDay * mNoOfDays - 1 tmpColumn2 = mDayStartColumn + mDayNoOfColumns + 3 * mNoOfTrainingTypes + 6 With shtDayGraphs.ChartObjects(2) For i = 0 To 3 .Chart.SeriesCollection(i + 1).Values = "=Dag!" & cellAddressR1C1(tmpRow1, tmpColumn2 + i, tmpRow2, tmpColumn2 + i) Next End With If mShowHeartRate Then ' heart rate tmpColumn2 = mDayStartColumn + mDayNoOfColumns + 3 * mNoOfTrainingTypes + 10 With shtDayGraphs.ChartObjects(4) For i = 0 To 7 .Chart.SeriesCollection(i + 1).Values = "=Dag!" & cellAddressR1C1(tmpRow1, tmpColumn2 + i, tmpRow2, tmpColumn2 + i) Next End With ' Borg tmpColumn2 = mDayStartColumn + mDayNoOfColumns + 3 * mNoOfTrainingTypes + 18 With shtDayGraphs.ChartObjects(5) For i = 0 To 7 .Chart.SeriesCollection(i + 1).Values = "=Dag!" & cellAddressR1C1(tmpRow1, tmpColumn2 + i, tmpRow2, tmpColumn2 + i) Next End With End If ' WEEK GRAPH SHEET shtWeekGraphs.Activate tmpRow1 = mWeekStartRow tmpRow2 = mWeekStartRow + mNoOfWeeks - 1 tmpColumn1 = mWeekStartColumn + mWeekNoOfColumns ' ill, injury, rest days tmpColumn2 = mWeekStartColumn + mWeekNoOfColumns + 1 + 3 * mNoOfTrainingTypes + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) + 18 With shtWeekGraphs.ChartObjects(5) For i = 0 To 2 With .Chart.SeriesCollection(i + 1) .Values = "=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + i, tmpRow2, tmpColumn2 + i) End With Next End With ' shape tmpColumn2 = mWeekStartColumn + mWeekNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 3 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtWeekGraphs.ChartObjects(7) With .Chart.SeriesCollection(1) .Values = "=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtWeekGraphs.Select ActiveSheet.ChartObjects(7).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With ' rest heart rate tmpColumn2 = mWeekStartColumn + mWeekNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 8 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtWeekGraphs.ChartObjects(6) With .Chart.SeriesCollection(1) .Values = "=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtWeekGraphs.Select ActiveSheet.ChartObjects(6).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With ' sleep time chartObjectIndex = 10 - IIf(Not mShowOTechnic, 2, 0) tmpColumn2 = mWeekStartColumn + mWeekNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 13 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtWeekGraphs.ChartObjects(chartObjectIndex) With .Chart.SeriesCollection(1) .Values = "=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtWeekGraphs.Select ActiveSheet.ChartObjects(chartObjectIndex).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Vecka!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With ' MONTH GRAPH SHEET shtMonthGraphs.Activate tmpRow1 = mMonthStartRow tmpRow2 = mMonthStartRow + mNoOfMonths - 1 tmpColumn1 = mMonthStartColumn + mMonthNoOfColumns ' ill, injury, rest days tmpColumn2 = mMonthStartColumn + mMonthNoOfColumns + 1 + 3 * mNoOfTrainingTypes + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) + 18 With shtMonthGraphs.ChartObjects(5) For i = 0 To 2 With .Chart.SeriesCollection(i + 1) .Values = "=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + i, tmpRow2, tmpColumn2 + i) End With Next End With ' shape tmpColumn2 = mMonthStartColumn + mMonthNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 3 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtMonthGraphs.ChartObjects(7) With .Chart.SeriesCollection(1) .Values = "=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtMonthGraphs.Select ActiveSheet.ChartObjects(7).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With ' rest heart rate tmpColumn2 = mMonthStartColumn + mMonthNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 8 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtMonthGraphs.ChartObjects(6) With .Chart.SeriesCollection(1) .Values = "=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtMonthGraphs.Select ActiveSheet.ChartObjects(6).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With ' sleep time chartObjectIndex = 10 - IIf(Not mShowOTechnic, 2, 0) tmpColumn2 = mMonthStartColumn + mMonthNoOfColumns + 1 + 3 * mNoOfTrainingTypes + 13 + IIf(mShowOTechnic, 9, 0) + IIf(mShowLegPlaces, 4, 0) With shtMonthGraphs.ChartObjects(chartObjectIndex) With .Chart.SeriesCollection(1) .Values = "=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 2, tmpRow2, tmpColumn2 + 2) shtMonthGraphs.Select ActiveSheet.ChartObjects(chartObjectIndex).Activate ActiveChart.SeriesCollection(1).ErrorBars.Select ExecuteExcel4Macro "ERRORBAR.Y(1,5,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 4, tmpRow2, tmpColumn2 + 4) & """,""=Månad!" & cellAddressR1C1(tmpRow1, tmpColumn2 + 3, tmpRow2, tmpColumn2 + 3) & """)" Selection.EndStyle = xlCap End With End With MsgBox "Diagrammen är nu korrekta. Klicka OK och stäng Visual Basic-fönstret genom att trycka Alt+Q. Spara sedan träningsdagboken.", vbInformation, "Träningsdagbok" End Sub