Skip to content

Instantly share code, notes, and snippets.

View stevehenderson's full-sized avatar

Steve Henderson stevehenderson

View GitHub Profile
@stevehenderson
stevehenderson / writeCSV
Last active December 17, 2015 08:39
VBA code to write worksheet calues to a CSV
Function writeCSV(csvPath As String) As String
'Create a CSV
Dim i As Integer
Dim lastUsedColumn As Integer
Dim done As Boolean
lastUsedColumn = 9
i = 1
done = False
While Not done
@stevehenderson
stevehenderson / gist:5581467
Last active December 17, 2015 08:39
VBA code for saving a csv to disk
Sub SendResults()
Dim OutApp As Object
Dim OutMail As Object
Dim currentPath As String
currentPath = Application.ActiveWorkbook.Path
currentPath = "\\se\ABETWorking\SEN0_CapstoneDA"
Dim csvPath As String
Dim emailBody As String
@stevehenderson
stevehenderson / EmailSheet
Last active December 17, 2015 08:39
VBA Code to attach a spreadsheet to an outlook email
Sub SendResultsFull()
Dim OutApp As Object
Dim OutMail As Object
Dim currentPath As String
currentPath = Application.ActiveWorkbook.Path
currentPath = "\\se\ABETWorking\SEN0_CapstoneDA"
Dim csvPath As String
Dim emailBody As String
@stevehenderson
stevehenderson / MouseClickOnCell
Created May 15, 2013 03:36
VBA code to handle mouse click events on cell selection inside Excel worksheets THIS NEEDS TO LIVE IN THE WORKSHEET SPACE
Option Explicit
Public lastSelectedRow As Integer
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If lastSelectedRow = 0 Then
lastSelectedRow = 17
@stevehenderson
stevehenderson / Copy_To_Worksheets
Last active December 17, 2015 08:39
VBA Code to split a column of factors into independent sheets. (VBA, Split, Sheets, Excel). Original code: http://www.rondebruin.nl/win/s3/win006_4.htm
Option Explicit
'Original code: http://www.rondebruin.nl/win/s3/win006_4.htm
Sub Copy_To_Worksheets()
Dim CalcMode As Long
Dim ws2 As Worksheet
Dim WSNew As Worksheet
Dim rng As Range
Dim cell As Range
Dim Lrow As Long
@stevehenderson
stevehenderson / findLastColumn
Created May 15, 2013 04:01
VBA helper function to find the final column of data on a worksheet (VBA, last, column, find, helper)
'A helper function to find the final column of data on a worksheet
'
'To use, provide the name of the worksheet
'The function assumes the data starts in cell A1
'and will return the column number of the column of data
'
'Author: Steve Henderson steven.henderson@usma.edu
'
Function findLastColumn(sheetName As String)
' Find the last column with data
@stevehenderson
stevehenderson / findFinalRow
Created May 15, 2013 04:03
A VBA helper function to find the final row of data on a worksheet (VBA, row, last, find)
'findFinalRow
'A helper function to find the final row of data on a worksheet
'
'To use, provide the name of the worksheet
'The function assumes the data starts in cell A1
'and will return the row number of the last row of data
'
'Author: Steve Henderson steven.henderson@usma.edu
'
Function findFinalRow(sheetName As String)
@stevehenderson
stevehenderson / Setup Pivot Table
Created May 15, 2013 04:05
VBA code to initialize a PivotTable
'SetupPivot: The following subroutine sets up a pivot table
'
'
' author: steven.henderson@usma.edu
'
'I received assitance from the following site:
'
@stevehenderson
stevehenderson / Pivot Table Settings
Created May 15, 2013 04:07
VBA code to configure a pivot table
'
' Configure the pivot table for analysis
'
Sub PvotTableTweak()
Dim pt As PivotTable
Dim WSD As Worksheet
Set WSD = Worksheets("DATA")
@stevehenderson
stevehenderson / Current Path
Created May 15, 2013 04:30
VBA code to get current path of workbook
'Path Only
Application.ActiveWorkbook.Path
'Whole enchilada
Application.ActiveWorkbook.FullName