2020. nov 06.

Google Scripts vs Excel VBA comparison

írta: dataanalyticsdemo
Google Scripts vs Excel VBA comparison

Google Sheets Scripts are Js based. This language is fundamentally different from VBA. Let's take a look to some comparisions.

Log a message to the designated logger.

Scripts:

function HelloWorld() {
Logger.log('Hello World'); //Javascript what else..
//console.log for Sheets;
}

VBA:

Sub HelloWorld()
Debug.Print ("Hello world ")
End Sub

Write in a specific cell:

Scripts:

function WriteToSheet() {
SpreadsheetApp.getActiveSheet().getRange('A2').setValue('Hello');
}

VBA:

Sub writetocell()
'in the most complicated case to resemble Js logic.
Application.ThisWorkbook.ActiveSheet.Range("A2").Value = "Hello"
'or simply
Range("A3").Value = "Hello"
End Sub

Display values of a loop in cells:

Scripts:

function loopit() {
for (var i = 1; i<=10;i++) {
var rng = 'B' + i.toString()
Logger.log(rng)
SpreadsheetApp.getActiveSheet().getRange(rng).setValue(i) }
}

VBA:

Sub writeloopvalues()
Dim i As Integer 'not even necessary if Option explicit is not enabled
For i = 1 To 10
Range("B" & i).Value = i
Next i
End Sub

 

 

As you can see, Scripts is a fundamentally more modern language with many concepts which are unknown in VBA.

Switching from VBA to Scripts can be hard at first, but it is worth it.

Szólj hozzá