Skip to content

Instantly share code, notes, and snippets.

View martinctc's full-sized avatar
🔥
Packaging up my workflows

Martin Chan martinctc

🔥
Packaging up my workflows
View GitHub Profile
@martinctc
martinctc / Scatter_Plotter.vbs
Last active February 1, 2018 18:13
[Scatter Plotter] Formats your data for plotting scatter diagrams in #Excel
Option Explicit
Sub ScatterPlotter()
'This VBA Excel code formats a three-column table (with header, data labels on lefter-most column) into a format suitable for creating a scatter diagram in Microsoft Excel / PowerPoint.
If MsgBox("When you begin, ensure that: (1) Col A is populated with desired horizontal labels, begin from A2 (downwards); (2) Col B is populated with desired x-axis values, begin from B2 (downwards); (3) Col C is populated with desired y-axis values, begin from C2 (downwards). Do you wish to continue?", vbYesNo) = vbNo Then Exit Sub
Dim activewb As Workbook
Dim origin_sheet As String
Dim oldsheet, newsheet As Worksheet
@martinctc
martinctc / DataCollater.vb
Last active March 1, 2019 21:25
[Collate two variables to output all possible combinations] #Excel
Sub Collater()
'You will have a two-column data table (with headers) and as many rows as you want.
'It doesn't matter whether your data consists of text or number - no "calculation" is run directly on the values.
'You want to "multiply out" your data to get all possible combinations.
'Ordering: Column A for the variable to repeat multiple times (e.g. Alice, Alice, Alice, Bob, Bob, Bob)
'Ordering: Column B for the variable to display in sequence (e.g. 15, 20, 30, 15, 20, 30)
'Leave first row blank
Dim wb As Workbook
@martinctc
martinctc / DArrayCreator.vb
Created October 23, 2016 21:01
Use this snippet for creating dynamic arrays from rows of data in Excel.
Sub DArrayCreator()
Dim wb As Workbook
Dim ws As Worksheet
Dim i, j, k As Integer
'Use this snippet for creating dynamic arrays from rows of data in Excel.
'Current snippet only allows for two columns of data.
'Enter source workbook location here
'Set wb = Workbooks.Open("C:\Users\Martin\Desktop\ArrayReplacer.xlsx")
Set wb = ActiveWorkbook
@martinctc
martinctc / PivotTableFilterer.vb
Created October 24, 2016 11:57
Filter all pivot tables on the same worksheet
Private Sub CommandButton1_Click()
Dim month_a, month_b, month_c, j As Integer
Dim currentm, defaultm As Long
Dim pvt As PivotTable
Dim coll As Collection
Dim PivotRefs, i As Variant
Application.ScreenUpdating = False
@martinctc
martinctc / check_update.R
Created November 5, 2016 17:15
Check and Update R
# installing/loading the package:
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr
# using the package:
updateR() # this will start the updating process of your R installation. It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.
@martinctc
martinctc / NPS_OE.R
Last active November 15, 2016 17:47
Basic Text Analytics for NPS Open-Ended Responses
library("tm")
library("wordcloud")
library("SnowballC")
library("RColorBrewer")
library("tcltk2")
tk_choose.dir(getwd(),"Choose a suitable folder")
db = file.choose()
data <-read.csv(db,stringsAsFactors = FALSE)
#Create text corpuses for Promoters and Detractors
@martinctc
martinctc / tablescraper.r
Last active November 28, 2016 22:59
Scraper for tables on websites
library("rvest")
url <- "https://bank.hangseng.com/1/2/rates/foreign-currency-tt-exchange-rates"
#Replace xpath with bits highlighting whole table on website using 'Inspect'
forex <- url %>%
html() %>%
html_nodes(xpath='//*[@id="viewns_7_0G3UNU10SD0MHTI7BJ91000000_:Display"]/div[1]/table') %>%
html_table()
forex <- forex[[1]]
@martinctc
martinctc / Data2Worksheets.vbs
Last active March 5, 2024 15:44
Split data into multiple worksheet based on column variables - edited from online sources
Sub parse_data()
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
'This macro splits data into multiple worksheets based on the variables on a column found in Excel.
@martinctc
martinctc / 0_reuse_code.js
Created November 28, 2016 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@martinctc
martinctc / Worksheet2CSV.vbs
Last active March 1, 2019 21:27
Save Worksheets in Excel file to CSV files (not my code) #Excel
Sub SaveWorksheetsAsCsv()
Dim WS As Excel.Worksheet
Dim SaveToDirectory As String
Dim CurrentWorkbook As String
Dim CurrentFormat As Long
CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat