SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Some common Excel functions
translated to Google Apps Script
Quick start to migration – part 1 Excel Liberation
Excel Liberation for details
Google Apps Script migration
Many people are either migrating to Google Docs or
using them alongside Microsoft Office Products
One inhibitor is where VBA automation has been
implemented in Excel workbooks. Google Apps
Script is essentially javaScript and has some
conceptual differences that provide a steep learning
curve when coming from Microsoft land.
A strategy for easing and speeding the transition is to
mimic common VBA functions in Google Apps
Script to minimize code conversion
Excel Liberation for details
Approach
javaScript differs considerably from VBA. This deck
does not cover learning javaScript, but rather
shows how some common VBA function might be
written in javaScript.
In order to minimize changes, we need to break
various javaScript conventions (like case
conventions for names)
A more detailed javaScript conversion primer and
some example project conversions can be found
here.
The functions discussed here are a subset of those
already available in a Google Apps Script
shareable library which you can include in your
project.
Excel Liberation for details
String functions - 1
VBA javaScript
RTrim(s) function RTrim(s) {
return CStr(s).replace(/ss*$/, "");
}
LTrim(s) function LTrim(s) {
return CStr(s).replace(/ss*$/, "");
}
Trim(s) function Trim(v) {
return LTrim(RTrim(v));
}
Len(v) function Len(v) {
return CStr(v).length ;
}
CStr(v) function CStr(v) {
return v===null || IsMissing(v) ? '' : v.toString() ;
}
Excel Liberation for details
String functions - 2
VBA javaScript
Left
(str,optLen
)
function Left(str,optLen) {
return Mid( str, 1 , optLen);
}
Right
(str,optLen
)
function Right(str,optLen) {
return Mid( str, 1 + Len(str) - fixOptional ( optLen, Len(str) ) );
}
Mid
(str,optSta
rt,optLen)
function Mid (str,optStart,optLen) {
var s = CStr(str);
var start = IsMissing (optStart) ? 0 : optStart - 1;
start = start < 0 ? 0 : start;
var length = IsMissing (optLen) ? Len(s) - start + 1 : optLen ;
return s.slice ( start, start + length);
}
Excel Liberation for details
String functions - 3
VBA javaScript
Split
(s,optDelim,
optLimit)
function Split(s,optDelim,optLimit) {
return CStr(s).split(fixOptional(optDelim,","),fixOptional(optLimit,-1));
};
LCase(s) function LCase(s) {
return CStr(s).toLowerCase();
}
function
UCase(s)
function UCase(s) {
return CStr(s).toUpperCase();
}
function
Chr(n)
function Chr(n) {
return String.fromCharCode(n);
}
function
Asc(s)
function Asc(s) {
return s.charCodeAt(0);
}
Excel Liberation for details
String functions - 4
VBA javaScript
InStr
(optStart,
inThisString
, lookFor,
optCompar
e)
function InStr(optStart,inThisString,lookFor,optCompare) {
// TODO optCompare
var start = fixOptional (optStart, 1);
var s = Mid (inThisString, start);
var p = s.indexOf(lookFor);
return (s && lookFor) ? (p == -1 ? 0 : p+start ): 0;
}
InStrRev
(inThisStrin
g,lookFor,
optStart,
optCompar
e)
function InStrRev(inThisString,lookFor,optStart,optCompare) {
// TODO optCompare
var start = fixOptional (optStart, -1);
var s = CStr(inThisString);
start = start == -1 ? Len(s) : start ;
return (s && lookFor) ? s.lastIndexOf(lookFor,start-1)+1 : 0;
}
Excel Liberation for details
Conversions
VBA javaScript
DateSerial
(y,m,d)
function DateSerial(y,m,d) {
return new Date(y,m,d);
}
Year (dt) function Year(dt) {
return dt.getFullYear();
}
CLng(v) function CLng(v) {
return isTypeNumber(v) ? Math.round(v) : parseInt(v) ;
}
CDbl(v) function CDbl(v) {
return parseFloat(v) ;
}
Excel Liberation for details
Tests
VBA javaScript
IsEmpty
(v)
function IsEmpty(v) {
return typeof(v) == "string" && v == Empty();
}
IsDate
(sDate)
function IsDate (sDate) {
var tryDate = new Date(sDate);
return (tryDate.toString() != "NaN" && tryDate != "Invalid
Date") ;
}
IsNumeric
(s)
function IsNumeric(s) {
return !isNaN(parseFloat(s)) && isFinite(s);
}
IsObject
(x)
function IsObject (x) {
return VarType(x) == 'object';
}
Excel Liberation for details
Part 2
That’s a brief introduction to some GAS
equivalents (almost) for VBA functions.
Part 2 will look at some of the more workbook
specific translations.
A more detailed javaScript conversion primer and
some example project conversions can be
found here.
The functions discussed here are a subset of
those already available in a Google Apps
Script shareable library which you can include
in your project.

Weitere ähnliche Inhalte

Andere mochten auch

Belajar Excel Tingkat Mahir
Belajar Excel Tingkat MahirBelajar Excel Tingkat Mahir
Belajar Excel Tingkat Mahir
AYU LESTARI
 

Andere mochten auch (8)

Using Groovy with Jenkins
Using Groovy with JenkinsUsing Groovy with Jenkins
Using Groovy with Jenkins
 
Belajar macro excel 2007
Belajar macro excel 2007Belajar macro excel 2007
Belajar macro excel 2007
 
Belajar Excel Tingkat Mahir
Belajar Excel Tingkat MahirBelajar Excel Tingkat Mahir
Belajar Excel Tingkat Mahir
 
Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007
 
17 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 201717 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 2017
 
Business Analysis Techniques
Business Analysis TechniquesBusiness Analysis Techniques
Business Analysis Techniques
 
INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]
 
Working With Big Data
Working With Big DataWorking With Big Data
Working With Big Data
 

Mehr von Bruce McPherson

Mehr von Bruce McPherson (15)

Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databases
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
 
Goa tutorial
Goa tutorialGoa tutorial
Goa tutorial
 
Do something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterDo something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilter
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email log
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a database
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
Dbabstraction
DbabstractionDbabstraction
Dbabstraction
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and Excel
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Some common VBA functions translated to Google Apps Script

  • 1. Some common Excel functions translated to Google Apps Script Quick start to migration – part 1 Excel Liberation
  • 2. Excel Liberation for details Google Apps Script migration Many people are either migrating to Google Docs or using them alongside Microsoft Office Products One inhibitor is where VBA automation has been implemented in Excel workbooks. Google Apps Script is essentially javaScript and has some conceptual differences that provide a steep learning curve when coming from Microsoft land. A strategy for easing and speeding the transition is to mimic common VBA functions in Google Apps Script to minimize code conversion
  • 3. Excel Liberation for details Approach javaScript differs considerably from VBA. This deck does not cover learning javaScript, but rather shows how some common VBA function might be written in javaScript. In order to minimize changes, we need to break various javaScript conventions (like case conventions for names) A more detailed javaScript conversion primer and some example project conversions can be found here. The functions discussed here are a subset of those already available in a Google Apps Script shareable library which you can include in your project.
  • 4. Excel Liberation for details String functions - 1 VBA javaScript RTrim(s) function RTrim(s) { return CStr(s).replace(/ss*$/, ""); } LTrim(s) function LTrim(s) { return CStr(s).replace(/ss*$/, ""); } Trim(s) function Trim(v) { return LTrim(RTrim(v)); } Len(v) function Len(v) { return CStr(v).length ; } CStr(v) function CStr(v) { return v===null || IsMissing(v) ? '' : v.toString() ; }
  • 5. Excel Liberation for details String functions - 2 VBA javaScript Left (str,optLen ) function Left(str,optLen) { return Mid( str, 1 , optLen); } Right (str,optLen ) function Right(str,optLen) { return Mid( str, 1 + Len(str) - fixOptional ( optLen, Len(str) ) ); } Mid (str,optSta rt,optLen) function Mid (str,optStart,optLen) { var s = CStr(str); var start = IsMissing (optStart) ? 0 : optStart - 1; start = start < 0 ? 0 : start; var length = IsMissing (optLen) ? Len(s) - start + 1 : optLen ; return s.slice ( start, start + length); }
  • 6. Excel Liberation for details String functions - 3 VBA javaScript Split (s,optDelim, optLimit) function Split(s,optDelim,optLimit) { return CStr(s).split(fixOptional(optDelim,","),fixOptional(optLimit,-1)); }; LCase(s) function LCase(s) { return CStr(s).toLowerCase(); } function UCase(s) function UCase(s) { return CStr(s).toUpperCase(); } function Chr(n) function Chr(n) { return String.fromCharCode(n); } function Asc(s) function Asc(s) { return s.charCodeAt(0); }
  • 7. Excel Liberation for details String functions - 4 VBA javaScript InStr (optStart, inThisString , lookFor, optCompar e) function InStr(optStart,inThisString,lookFor,optCompare) { // TODO optCompare var start = fixOptional (optStart, 1); var s = Mid (inThisString, start); var p = s.indexOf(lookFor); return (s && lookFor) ? (p == -1 ? 0 : p+start ): 0; } InStrRev (inThisStrin g,lookFor, optStart, optCompar e) function InStrRev(inThisString,lookFor,optStart,optCompare) { // TODO optCompare var start = fixOptional (optStart, -1); var s = CStr(inThisString); start = start == -1 ? Len(s) : start ; return (s && lookFor) ? s.lastIndexOf(lookFor,start-1)+1 : 0; }
  • 8. Excel Liberation for details Conversions VBA javaScript DateSerial (y,m,d) function DateSerial(y,m,d) { return new Date(y,m,d); } Year (dt) function Year(dt) { return dt.getFullYear(); } CLng(v) function CLng(v) { return isTypeNumber(v) ? Math.round(v) : parseInt(v) ; } CDbl(v) function CDbl(v) { return parseFloat(v) ; }
  • 9. Excel Liberation for details Tests VBA javaScript IsEmpty (v) function IsEmpty(v) { return typeof(v) == "string" && v == Empty(); } IsDate (sDate) function IsDate (sDate) { var tryDate = new Date(sDate); return (tryDate.toString() != "NaN" && tryDate != "Invalid Date") ; } IsNumeric (s) function IsNumeric(s) { return !isNaN(parseFloat(s)) && isFinite(s); } IsObject (x) function IsObject (x) { return VarType(x) == 'object'; }
  • 10. Excel Liberation for details Part 2 That’s a brief introduction to some GAS equivalents (almost) for VBA functions. Part 2 will look at some of the more workbook specific translations. A more detailed javaScript conversion primer and some example project conversions can be found here. The functions discussed here are a subset of those already available in a Google Apps Script shareable library which you can include in your project.