Skip to content

Commit

Permalink
Merge pull request #42 from byronwall/ongoing-changes-charts
Browse files Browse the repository at this point in the history
Brings in ongoing changes
  • Loading branch information
byronwall committed Dec 4, 2015
2 parents 75fcbd0 + 18afa13 commit 1166c64
Show file tree
Hide file tree
Showing 18 changed files with 546 additions and 153 deletions.
16 changes: 9 additions & 7 deletions src/code/Chart_Axes.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Chart_Axes"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Chart_Axes
' Author : @byronwall
Expand Down Expand Up @@ -68,20 +70,20 @@ End Sub
'---------------------------------------------------------------------------------------
'
Sub Chart_FitAxisToMaxAndMin(xlCat As XlAxisType)

Dim first As Boolean
first = True

Dim cht_obj As ChartObject

For Each cht_obj 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 cht As Chart
Set cht = cht_obj.Chart

Dim ser As series
For Each ser In cht.SeriesCollection

Dim min_val As Double, max_val As Double
Dim min_val As Double
Dim max_val As Double

If xlCat = xlCategory Then

Expand Down Expand Up @@ -124,7 +126,7 @@ End Sub
' Flags : not-used
'---------------------------------------------------------------------------------------
'
Sub Chart_YAxisRangeWithAvgAndStdev()
Public Sub Chart_YAxisRangeWithAvgAndStdev()
Dim dbl_std As Double

dbl_std = CDbl(InputBox("How many standard deviations to include?"))
Expand Down
6 changes: 6 additions & 0 deletions src/code/Chart_Format.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Chart_Format"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Chart_Format
' Author : @byronwall
Expand Down Expand Up @@ -111,6 +113,10 @@ Sub Chart_AxisTitleIsSeriesTitle()

cht.Axes(xlValue, ser.AxisGroup).HasTitle = True
cht.Axes(xlValue, ser.AxisGroup).AxisTitle.Text = b_ser.name

'2015 11 11, adds the x-title assuming that the name is one cell above the data
cht.Axes(xlCategory).HasTitle = True
cht.Axes(xlCategory).AxisTitle.Text = b_ser.XValues.Cells(1, 1).Offset(-1).Value

Next ser
Next cht_obj
Expand Down
2 changes: 2 additions & 0 deletions src/code/Chart_Helpers.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Chart_Helpers"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Chart_Helpers
' Author : @byronwall
Expand Down
51 changes: 51 additions & 0 deletions src/code/Chart_Processing.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,57 @@ Attribute VB_Name = "Chart_Processing"

Option Explicit

Public Sub Chart_CreateChartWithSeriesForEachColumn()
'will create a chart that includes a series with no x value for each column

Dim rng_data As Range
Set rng_data = GetInputOrSelection("Select chart data")

'create a chart
Dim cht_obj As ChartObject
Set cht_obj = ActiveSheet.ChartObjects.Add(0, 0, 300, 300)

cht_obj.Chart.ChartType = xlXYScatter

Dim rng_col As Range
For Each rng_col In rng_data.Columns

Dim rng_chart As Range
Set rng_chart = RangeEnd(rng_col.Cells(1, 1), xlDown)

Dim b_ser As New bUTLChartSeries
Set b_ser.Values = rng_chart

b_ser.AddSeriesToChart cht_obj.Chart
Next

End Sub

Public Sub Chart_CopyToSheet()

Dim cht_obj As ChartObject

Dim obj_all As Object
Set obj_all = Selection

Dim msg_newSheet As VbMsgBoxResult
msg_newSheet = MsgBox("New sheet?", vbYesNo, "New sheet?")

Dim sht_out As Worksheet
If msg_newSheet = vbYes Then
Set sht_out = Worksheets.Add()
Else
Set sht_out = Application.InputBox("Pick a cell on a sheet", "Pick sheet", Type:=8).Parent
End If

For Each cht_obj In Chart_GetObjectsFromObject(obj_all)
cht_obj.Copy

sht_out.Paste
Next

sht_out.Activate
End Sub

Sub Chart_SortSeriesByName()
'this will sort series by names
Expand Down
8 changes: 7 additions & 1 deletion src/code/Chart_Series.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Chart_Series"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Chart_Series
' Author : @byronwall
Expand Down Expand Up @@ -42,7 +44,11 @@ Sub Chart_AddTrendlineToSeriesAndColor()
Set trend = ser.Trendlines.Add()
trend.Type = xlLinear
trend.Border.Color = ser.MarkerBackgroundColor
trend.name = b_ser.name

'2015 11 06 test to avoid error without name
If Not b_ser.name Is Nothing Then
trend.name = b_ser.name
End If

trend.DisplayEquation = True
trend.DisplayRSquared = True
Expand Down
27 changes: 22 additions & 5 deletions src/code/Formatting_Helpers.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Formatting_Helpers"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Formatting_Helpers
' Author : @byronwall
Expand Down Expand Up @@ -131,11 +133,13 @@ Public Sub Colorize()
Set rngToColor = GetInputOrSelection("Select range to color")
Dim lastrow As Integer
lastrow = rngToColor.Rows.count


Dim likevalues As VbMsgBoxResult
likevalues = MsgBox("Do you want to keep duplicate values the same color?", vbYesNo)

If likevalues = vbNo Then


Dim i As Integer
For i = 1 To lastrow
If i Mod 2 = 0 Then
rngToColor.Rows(i).Interior.Color = RGB(200, 200, 200)
Expand Down Expand Up @@ -194,8 +198,10 @@ Sub CombineCells()

'Read input rows into a single string
Dim strOutput As String
Dim i As Integer
For i = 1 To x
strOutput = vbNullString
Dim j As Integer
For j = 1 To y
strOutput = strOutput & strDelim & rngInput(i, j)
Next
Expand Down Expand Up @@ -296,6 +302,8 @@ Sub CopyTranspose()
errCancel:
End Sub



'---------------------------------------------------------------------------------------
' Procedure : CreateConditionalsForFormatting
' Author : @byronwall
Expand All @@ -310,7 +318,8 @@ Sub CreateConditionalsForFormatting()
'add these in as powers of 3, starting at 1 = 10^0
Dim arrMarkers As Variant
arrMarkers = Array("", "k", "M", "B")


Dim i As Integer
For i = UBound(arrMarkers) To 0 Step -1

With rngInput.FormatConditions.Add(xlCellValue, xlGreaterEqual, 10 ^ (3 * i))
Expand Down Expand Up @@ -341,6 +350,8 @@ Sub ExtendArrayFormulaDown()
Set rngArrForm = Selection

For Each RngArea In rngArrForm.Areas

Dim c As Range
For Each c In RngArea.Cells

If c.HasArray Then
Expand Down Expand Up @@ -382,6 +393,9 @@ Sub MakeHyperlinks()
On Error GoTo errHandler
Dim rngEval As Range
Set rngEval = GetInputOrSelection("Select the range of cells to convert to hyperlink")

'TODO: choose a better variable name
Dim c As Range
For Each c In rngEval
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=c
Next c
Expand All @@ -399,7 +413,8 @@ End Sub
'---------------------------------------------------------------------------------------
'
Sub OutputColors()


Dim i As Integer
For i = 1 To 10
ActiveCell.Offset(i).Interior.Color = Chart_GetColor(i)
Next i
Expand All @@ -419,6 +434,7 @@ Sub SelectedToValue()
On Error GoTo errHandler
Set rng = GetInputOrSelection("Select the formulas you'd like to convert to static values")

Dim c As Range
For Each c In rng
c.Value = c.Value
Next c
Expand Down Expand Up @@ -587,7 +603,8 @@ Sub TrimSelection()
Dim rngToTrim As Range
On Error GoTo errHandler
Set rngToTrim = GetInputOrSelection("Select the formulas you'd like to convert to static values")


Dim c As Range
For Each c In rngToTrim
c.Value = Trim(c.Value)
Next c
Expand Down
4 changes: 3 additions & 1 deletion src/code/RandomCode.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "RandomCode"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : RandomCode
' Author : @byronwall
Expand Down Expand Up @@ -174,7 +176,7 @@ Sub Rand_DownloadFromSheet()

For Each rng_addr In Range("B2:B35")

Download_File rng_add, str_folder & rng_addr.Offset(, 1)
Download_File rng_addr, str_folder & rng_addr.Offset(, 1)

Next rng_addr

Expand Down
6 changes: 4 additions & 2 deletions src/code/Ribbon_Callbacks.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Ribbon_Callbacks"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Ribbon_Callbacks
' Author : @byronwall
Expand Down Expand Up @@ -113,7 +115,7 @@ Public Sub btn_convertValue_onAction(control As IRibbonControl)
End Sub

Public Sub btn_copyClear_onAction(control As IRibbonControl)
CopyClear
MsgBox "Copy clear is missing"
End Sub

Public Sub btn_cutTranspose_onAction(control As IRibbonControl)
Expand Down Expand Up @@ -162,7 +164,7 @@ Public Sub btn_protect_onAction(control As IRibbonControl)
End Sub

Public Sub btn_rmvComments_onAction(control As IRibbonControl)
RemoveComments
MsgBox "RemoveComments missing"
End Sub

Public Sub btn_seriesSplit_onAction(control As IRibbonControl)
Expand Down
7 changes: 5 additions & 2 deletions src/code/Sheet_Helpers.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "Sheet_Helpers"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : Sheet_Helpers
' Author : @byronwall
Expand All @@ -24,9 +26,10 @@ Sub LockAllSheets()
Application.ScreenUpdating = False

'Changed to activeworkbook so if add-in is not installed, it will target the active book rather than the xlam
For Each Sheet In ActiveWorkbook.Sheets
Dim sheet As Worksheet
For Each sheet In ActiveWorkbook.Sheets
On Error Resume Next
Sheet.Protect (pass)
sheet.Protect (pass)
Next

Application.ScreenUpdating = True
Expand Down
2 changes: 2 additions & 0 deletions src/code/SubsFuncs_Helpers.bas
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Attribute VB_Name = "SubsFuncs_Helpers"
Option Explicit

'---------------------------------------------------------------------------------------
' Module : SubsFuncs_Helpers
' Author : @byronwall
Expand Down
Loading

0 comments on commit 1166c64

Please sign in to comment.