VBA is the language, in which excel macros were written. Google sheets only supports Google apps script as a macro language. Is there a direct or automatic way to convert a VBA script to a Google Apps Script script without rewriting the code?
Here is a sample VBA script, that I am trying to convert:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngStart As Range, rngCrit As Range
Set rngStart = Range("A3")
Set rngCrit = Range("B1")
On Error GoTo ExitPoint
Application.EnableEvents = False
If Not Intersect(Target, rngCrit) Is Nothing Then
Range(rngStart, Cells(Rows.Count, rngStart.Column).End(xlUp)).ClearContents
If Val(rngCrit) > 0 Then
With rngStart.Resize(Val(rngCrit))
.Value = "=ROW()-" & rngStart.Row - 1
.Value = .Value
End With
End If
End If
ExitPoint:
Set rngStart = Nothing
Set rngCrit = Nothing
Application.EnableEvents = True
End Sub
What I've tried:
I've tried to substitute some of the commands with some of the equivalent Google Scripts. My issue is I am thinking too linear. I am trying to code the same exact way as VBA and just trying to switch keywords from VBA to ones in Google Script. I was hoping there was a direct method.