Skip to content

Commit

Permalink
Added a distance function
Browse files Browse the repository at this point in the history
The distance function is good to compare data sets.  Also starting to
work through the issues reported by RubberDuck.
  • Loading branch information
byronwall committed Dec 3, 2015
1 parent bbdb56c commit 2f488fe
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/code/Chart_Axes.bas
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Sub Chart_FitAxisToMaxAndMin(xlCat As XlAxisType)
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 @@ -125,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
54 changes: 54 additions & 0 deletions src/code/Testing.bas
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
Attribute VB_Name = "Testing"
Option Explicit

Public Sub ComputeDistanceMatrix()

'get the range of inputs, along with input name
Dim rng_input As Range
Set rng_input = Application.InputBox("Select input data", "Input", Type:=8)

'Dim rng_ID As Range
'Set rng_ID = Application.InputBox("Select ID data", "ID", Type:=8)

'turning off updates makes a huge difference here... could also use array for output
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

'create new workbook
Dim wkbk As Workbook
Set wkbk = Workbooks.Add

Dim rng_out As Range
Set rng_out = wkbk.Sheets(1).Range("A1")

'loop through each row with each other row
Dim rng_row1 As Range
Dim rng_row2 As Range

For Each rng_row1 In rng_input.Rows
For Each rng_row2 In rng_input.Rows

'loop through each column and compute the distance
Dim dbl_dist_sq As Double
dbl_dist_sq = 0

Dim int_col As Integer
For int_col = 1 To rng_row1.Cells.count
dbl_dist_sq = dbl_dist_sq + (rng_row1.Cells(1, int_col) - rng_row2.Cells(1, int_col)) ^ 2
Next

'take the sqrt of that value and output
rng_out.Value = dbl_dist_sq ^ 0.5

'get to next column for output
Set rng_out = rng_out.Offset(, 1)
Next

'drop down a row and go back to left edge
Set rng_out = rng_out.Offset(1).End(xlToLeft)
Next

Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Sub RemoveAllLegends()

Dim cht_obj As ChartObject
Expand Down
21 changes: 21 additions & 0 deletions src/code/Usability.bas
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ Sub ConvertSelectionToCsv()

End Sub

Public Sub CopyCellAddress()
'---------------------------------------------------------------------------------------
' Procedure : CopyCellAddress
' Author : @byronwall
' Date : 2015 12 03
' Purpose : Copies the current cell address to the clipboard for paste use in a formula
'---------------------------------------------------------------------------------------
'

'TODO: this need to get a button or a keyboard shortcut for easy use
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject

Dim rng_sel As Range
Set rng_sel = Selection

clipboard.SetText rng_sel.Address(True, True, xlA1, True)
clipboard.PutInClipboard
End Sub


'---------------------------------------------------------------------------------------
' Procedure : CopyClear
' Author : @byronwall
Expand Down

0 comments on commit 2f488fe

Please sign in to comment.