Convert VBA to Google Sheets Apps Script

joeyrain

New Member
Joined
Dec 4, 2018
Messages
5
I have a macro formula that i use in excel that I would like to transport the macro to google but it's not working...

What the macro is suppose to do is to sort the columns Based On The Values Of G1 To V1...When When Sorting It Looks At These Values Only So If G1 Has A Value Of 15 And H1 Has A Value Of 10, Then The End Result Of The Sorting Is Only To Switch Columns Of G To H And H To G... We Are Sorting The Columns Not The Rows Based On G1 To V1. The Values In Each Row Stay In The Same Row. We Do Not Want The Rows To Be Sorted We Only Want The Columns To Switch Places Based On The Values Found From G1 To V1

The Macro below works in excel, but it does not translate to google sheets. Can anyone help?



Sub SortML()
'
' SortML Macro
'
' Keyboard Shortcut: Ctrl+z
'
ActiveWorkbook.Worksheets("Draft").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Draft").Sort.SortFields.Add Key:=Range( _
"G1:V1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Draft").Sort.SortFields.Add Key:=Range( _
"G1:V1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Draft").Sort
.SetRange Range("G1:V56")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With

For i = 66 To 81
Range(Chr(i) & "1") = i - 65
Next i

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top