Skip to content

Instantly share code, notes, and snippets.

View bnjcbsn's full-sized avatar

Ben Jacobson bnjcbsn

  • Saginaw, TX
View GitHub Profile
@bnjcbsn
bnjcbsn / replace_with_ave.bas
Created December 19, 2017 22:45
Excel VBA, replace highlighted cells with their average
Public Sub spreads()
' no error traps!! YOYO
scnt = Selection.Count
ssum = Application.WorksheetFunction.Sum(Selection)
pastingValue = ssum / scnt
Selection.Value = pastingValue
End Sub
@bnjcbsn
bnjcbsn / r_send_html_email.txt
Created February 28, 2016 17:00
R send html email with inline images such as plots
So, this works on Windows 7 machine running Outlook 2010 and R 3.2.3 in RStudio.
Two files: testrhtml.rhtml and send_email.R
First is just the default results of creating a new R HTML file with output to testrhtml.html and unnamed-chunk-2-1.png.
Okay, I've really only done this slightly manual and with one plot so far.
***testrhtml.rhtml***
<html>
<head>
Attribute VB_Name = "basUnpivot_20151204"
Sub unPivot_20()
Dim oTarget As Range
Dim oSource As Range
Dim oCell As Range
' original http://superuser.com/a/583083/529888
' posted by http://superuser.com/users/217174/tjmelrose
' will unpivot a table in Excel 2010
' Access VBA
' loops through a single column recordset and builds a csv text string
' that can be inserted into a query
' modified from unknown internet sources
' my NY resolution is to capture sources when culling ideas from internet
If rs.RecordCount <> 0 Then
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
Attribute VB_Name = "basReadInData"
Public Sub doProcessAllFiles()
' Ben Jacobson 2015
' reads and builds a data table of specific cells from all workbooks in same folder
' I have failed to note where I copied sections from, so I apologize. This is why I give back.
Dim sThisFilePath As String
Dim sFile As String
Dim wbk As Workbook