Forum Discussion
Patrick_virtualFD
Jan 18, 2023Brass Contributor
Office script version of VBA for column autofit?
hi everyone, Do you know if there's a way to mimic the behaviour of the VBA command cells.entirecolumn.autofit using Office Script? I've managed to get this behaviour on a particular table (a...
- Feb 03, 2023You can use something like:
selectedSheet.getRange("D8:J8").getFormat().autofitColumns();
See:
https://learn.microsoft.com/en-gb/office/dev/scripts/tutorials/excel-read-tutorial
b-gonzalez
Jan 23, 2023Copper Contributor
Is the VBA code triggered by an event? e.g. worksheet_change? If so that won't work in Office Scripts as Office Scripts doesn't currently support events.
Patrick_virtualFD
Jan 24, 2023Brass Contributor
hi there,
No, with the VBA code it just applies to the worksheet under any circumstances - you type anything into the sheet and it will flex the column widths accordingly, live as you type.
I don't know VBA - is this sort of real-time behaviour governed by an 'event'?
No, with the VBA code it just applies to the worksheet under any circumstances - you type anything into the sheet and it will flex the column widths accordingly, live as you type.
I don't know VBA - is this sort of real-time behaviour governed by an 'event'?
- b-gonzalezJan 24, 2023Copper ContributorCould you share the VBA code? If so I would be able to confirm
- Patrick_virtualFDFeb 06, 2023Brass ContributorPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.EntireColumn.AutoFit
End Sub