Forum Discussion

B_H33's avatar
B_H33
Copper Contributor
Nov 02, 2021

Help to convert VBA to Excel Online script

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, _
Orientation:=xlTopToBottom
ActiveSheet.Protect "Brooke"
End Sub

6 Replies

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor
    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?
    • B_H33's avatar
      B_H33
      Copper Contributor
      Hi Jan,
      I only want to auto sort column F.
      Can you help me write a script?
    • PeterBartholomew1's avatar
      PeterBartholomew1
      Silver Contributor

      JKPieterse 

      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.