Help to convert VBA to Excel Online script

Occasional Contributor
Hi, I need help converting a VBA to a Script for Excel Online.
Can anyone help me with this??
VBA code is:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
ActiveSheet.Unprotect "Brooke"
Range("F1").Sort Key1:=Range("F2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
ActiveSheet.Protect "Brooke"
End Sub

6 Replies
Hi @B_H33
Office Script does not support event code like your Worksheet_Change event, you can only start scripts manually. Have you tried to record the steps using the script recorder?

@Jan Karel Pieterse 

I found it somewhat frustrating.  The only things I tend to use VBA for are to create sketches to illustrate engineering data using shapes and for event handling to create interactive user interfaces.  Nothing of which works on-line.


Once Lambda functions are fully functional, many of the process steps that used to be implemented using VBA could be achieved with worksheet formula.  In the present case, the data input table could be left in its original sequence whilst a formula would give the sorted representation on a separate worksheet.

Hi Jan,
I only want to auto sort column F.
Can you help me write a script?
@B_H33 Have you tried recording a script yet?
Yes I did today. But when I run it it only sorts column F and doesn't extend to other columns...
Please paste your current script result here, I'll see what I can do.