Skip to content

Commit

Permalink
Merge pull request #58 from byronwall/local_changes
Browse files Browse the repository at this point in the history
Adds updating, tons of code, and better names
  • Loading branch information
byronwall authored Oct 11, 2016
2 parents 110010e + 71d6e86 commit e48677a
Show file tree
Hide file tree
Showing 29 changed files with 2,669 additions and 2,107 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ If you want to contribute a feature to the add-in or improve the code in some ot
- commit and submit a pull request

Why? This workflow has been adopted because Excel/VBA files have severe limitations for version control. An `xlam` file is a zipped folder with a number of binary files inside the zip. There are a couple of useful add-ins which help manage this, but I would prefer to not dictate what add-ins are installed. Given that, this workflow and build scripts allow for changes to the underlying VBA code and Ribbon interface to be properly tracked.

##Structure of the repo
The repo contains the source code, documentation, and several scripts used to generate the source from the xlam file.

Folder structure:

- docs: contains Markdown files to explain the functions of the add-in
- scripts: contains the build scripts which are used to convert the xlam file to repo-ready source code and to convert the source code to a usable xlam file.
- src: this folders contains the actual source code including an unzipped version of the xlam file
- code: this folder contains .bas, .cls, and .frx files which represent the source of the VBA code
- package: this is an unzipped version of the xlam file which allows for the XML driving the add-in to be tracked correctly
Binary file removed bUTL.xlam
Binary file not shown.
166 changes: 77 additions & 89 deletions src/code/Chart_Axes.bas
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
Attribute VB_Name = "Chart_Axes"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Chart_Axes
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Contains code related to chart axes
'---------------------------------------------------------------------------------------

'---------------------------------------------------------------------------------------
' Procedure : Chart_Axis_AutoX
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Reverts the x axis of a chart back to Auto
'---------------------------------------------------------------------------------------
'
Sub Chart_Axis_AutoX()

'---------------------------------------------------------------------------------------
' Procedure : Chart_Axis_AutoX
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Reverts the x axis of a chart back to Auto
'---------------------------------------------------------------------------------------
'
Dim chartObj As ChartObject
For Each chartObj In Chart_GetObjectsFromObject(Selection)
Dim myChart As Chart

Dim cht As Chart
Set cht = chartObj.Chart

Dim xAxis As Axis

Set myChart = chartObj.Chart

Set xAxis = myChart.Axes(xlCategory)
Set xAxis = cht.Axes(xlCategory)
xAxis.MaximumScaleIsAuto = True
xAxis.MinimumScaleIsAuto = True
xAxis.MajorUnitIsAuto = True
Expand All @@ -35,24 +25,22 @@ Sub Chart_Axis_AutoX()

End Sub

'---------------------------------------------------------------------------------------
' Procedure : Chart_Axis_AutoY
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Reverts the Y axis of a chart back to Auto
'---------------------------------------------------------------------------------------
'
Sub Chart_Axis_AutoY()

Sub Chart_Axis_AutoY()
'---------------------------------------------------------------------------------------
' Procedure : Chart_Axis_AutoY
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Reverts the Y axis of a chart back to Auto
'---------------------------------------------------------------------------------------
'
Dim chartObj As ChartObject
For Each chartObj In Chart_GetObjectsFromObject(Selection)
Dim myChart As Chart

Dim cht As Chart
Set cht = chartObj.Chart

Dim yAxis As Axis

Set myChart = chartObj.Chart

Set yAxis = myChart.Axes(xlValue)
Set yAxis = cht.Axes(xlValue)
yAxis.MaximumScaleIsAuto = True
yAxis.MinimumScaleIsAuto = True
yAxis.MajorUnitIsAuto = True
Expand All @@ -62,92 +50,92 @@ Sub Chart_Axis_AutoY()

End Sub

'---------------------------------------------------------------------------------------
' Procedure : Chart_FitAxisToMaxAndMin
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Iterates through all series and sets desired axis to max/min of data
'---------------------------------------------------------------------------------------
'
Sub Chart_FitAxisToMaxAndMin(typeOfAxis As XlAxisType)

Sub Chart_FitAxisToMaxAndMin(axisType As XlAxisType)
'---------------------------------------------------------------------------------------
' Procedure : Chart_FitAxisToMaxAndMin
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Iterates through all series and sets desired axis to max/min of data
'---------------------------------------------------------------------------------------
'
Dim chartObj As ChartObject
For Each chartObj In Chart_GetObjectsFromObject(Selection)
'2015 11 09 moved first inside loop so that it works for multiple charts
Dim first As Boolean
first = True
Dim isFirst As Boolean
isFirst = True

Dim myChart As Chart
Set myChart = chartObj.Chart
Dim cht As Chart
Set cht = chartObj.Chart

Dim mySeries As series
For Each mySeries In myChart.SeriesCollection
Dim chtSeries As series
For Each chtSeries In cht.SeriesCollection

Dim minimumValue As Double
Dim maximumValue As Double
Dim minValue As Double
Dim maxValue As Double

If typeOfAxis = xlCategory Then
If axisType = xlCategory Then

minimumValue = Application.Min(mySeries.XValues)
maximumValue = Application.Max(mySeries.XValues)
minValue = Application.Min(chtSeries.XValues)
maxValue = Application.Max(chtSeries.XValues)

ElseIf typeOfAxis = xlValue Then
ElseIf axisType = xlValue Then

minimumValue = Application.Min(mySeries.Values)
maximumValue = Application.Max(mySeries.Values)
minValue = Application.Min(chtSeries.Values)
maxValue = Application.Max(chtSeries.Values)

End If


Dim myAxis As Axis
Set myAxis = myChart.Axes(typeOfAxis)
Dim ax As Axis
Set ax = cht.Axes(axisType)

Dim newMinimum As Boolean
Dim newMaximum As Boolean

newMaximum = maximumValue > myAxis.MaximumScale
newMinimum = minimumValue < myAxis.MinimumScale
Dim isNewMax As Boolean, isNewMin As Boolean
isNewMax = maxValue > ax.MaximumScale
isNewMin = minValue < ax.MinimumScale

If first Or newMinimum Then
myAxis.MinimumScale = minimumValue
If isFirst Or isNewMin Then
ax.MinimumScale = minValue
End If
If first Or newMaximum Then
myAxis.MaximumScale = maximumValue
If isFirst Or isNewMax Then
ax.MaximumScale = maxValue
End If

first = False
Next mySeries
isFirst = False
Next chtSeries
Next chartObj

End Sub

'---------------------------------------------------------------------------------------
' Procedure : Chart_YAxisRangeWithAvgAndStdev
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Sets a chart's Y axis to a number of standard deviations
' Flags : not-used
'---------------------------------------------------------------------------------------
'
Public Sub Chart_YAxisRangeWithAvgAndStdev()
Dim numberStandardDeviations As Double

numberStandardDeviations = CDbl(InputBox("How many standard deviations to include?"))
Public Sub Chart_YAxisRangeWithAvgAndStdev()
'---------------------------------------------------------------------------------------
' Procedure : Chart_YAxisRangeWithAvgAndStdev
' Author : @byronwall
' Date : 2015 07 24
' Purpose : Sets a chart's Y axis to a number of standard deviations
' Flags : not-used
'---------------------------------------------------------------------------------------
'
Dim numberOfStdDevs As Double

numberOfStdDevs = CDbl(InputBox("How many standard deviations to include?"))

Dim chartObj As ChartObject

For Each chartObj In Chart_GetObjectsFromObject(Selection)

Dim mySeries As series
Set mySeries = chartObj.Chart.SeriesCollection(1)
Dim chtSeries As series
Set chtSeries = chartObj.Chart.SeriesCollection(1)

Dim averageValue As Double
Dim standardValue As Double
Dim avgValue As Double
Dim stdValue As Double

averageValue = WorksheetFunction.Average(mySeries.Values)
standardValue = WorksheetFunction.StDev(mySeries.Values)
avgValue = WorksheetFunction.Average(chtSeries.Values)
stdValue = WorksheetFunction.StDev(chtSeries.Values)

chartObj.Chart.Axes(xlValue).MinimumScale = averageValue - standardValue * numberStandardDeviations
chartObj.Chart.Axes(xlValue).MaximumScale = averageValue + standardValue * numberStandardDeviations
chartObj.Chart.Axes(xlValue).MinimumScale = avgValue - stdValue * numberOfStdDevs
chartObj.Chart.Axes(xlValue).MaximumScale = avgValue + stdValue * numberOfStdDevs

Next

Expand Down
Loading

0 comments on commit e48677a

Please sign in to comment.