Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
danwagnerco / transpose_horizontal_data_to_vertical.vb
Last active August 27, 2015 03:20
This macro "de-pivots" a few columns (and repeats the corresponding rows) to make forming a pivot table easy
Option Explicit
Public Sub TransposeHorizontalToVertical()
Dim lngLastRow As Long, lngIdx As Long, lngOutputLastRow As Long, _
lngDetailsIdx As Long, lngTargetRow As Long, lngTargetCol As Long
Dim wksInput As Worksheet, wksOutput As Worksheet
Dim varDetailNames As Variant, varMonthNames As Variant, _
varDetails As Variant, varValues As Variant
Dim varDetailsKey As Variant, varValuesKey As Variant
Dim dicDetails As Scripting.Dictionary, dicValues As Scripting.Dictionary
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUT : SheetName, the name (string) of the sheet we're looking for
'OUTPUT : True or false (sheet was found, sheet was not found)
'SPECIAL CASE : none
'EXAMPLES BELOW:
'
'assume that a sheet named "YaGotMe" exists
'DoesSheetExist("YaGotMe")
'>> True
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUT : Sheet, the worksheet on which you'd like all filters cleared
'DESCRIPTION : this sub will remove all filters on a worksheet safely
'
Public Sub ClearAllFilters(Sheet As Worksheet)
With Sheet
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
@danwagnerco
danwagnerco / _vimrc
Last active August 29, 2015 14:12
Airline-specific _vimrc settings
set guifont=Meslo\ LG\ M\ for\ Powerline:h9 " <~ set the font
set encoding=utf-8 " <~ set the encoding
let g:airline_powerline_fonts=1 " <~ activate the font in airline
@danwagnerco
danwagnerco / _vimrc
Last active August 29, 2015 14:13
Consolas setting for vim-airline inside your _vimrc
" set guifont=Meslo\ LG\ M\ for\ Powerline:h9 " <~ set the font
set guifont=Powerline\ Consolas:h11 " <~ set the font
set encoding=utf-8 " <~ set the encoding
let g:airline_powerline_fonts=1 " <~ activate the font in airline
@danwagnerco
danwagnerco / config.yml
Created January 9, 2015 12:46
An example DevKit yml file
# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
@danwagnerco
danwagnerco / _vimrc
Created January 31, 2015 18:04
Puts temp and swap files elsewhere when using Vim
set backupdir=%HOMEPATH%/temp
set directory=%HOMEPATH%/temp
@danwagnerco
danwagnerco / Gemfile
Created February 13, 2015 15:11
An example Gemfile config
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
gem "rspec", :require => "spec"
gem "timecop"
gem "ocra"
@danwagnerco
danwagnerco / date_type.rb
Last active August 29, 2015 14:16
Why does self.path = work instead of just path = ?
class DateType
attr_reader :entry
attr_accessor :path, :error_state
def initialize(entry)
@entry = entry.to_s
@path = ""
@error_state = false
end
@danwagnerco
danwagnerco / convert_yyyymmdd_to_date.vb
Created June 11, 2015 02:54
This user-defined function (UDF) converts numbers in format YYYYMMDD to actual Excel dates
Option Explicit
Public Function CONVERT_YYYYMMDD_TO_DATE(rng As Range) As Date
Dim strText As String
'First we get the raw text from the Range (i.e. the Cell)
strText = rng.Text
'Then we can slice and dice the number, feeding it all into DateSerial
CONVERT_YYYYMMDD_TO_DATE = DateSerial(Left(strText, 4), _
Mid(strText, 5, 2), _