Created
December 30, 2014 04:31
-
-
Save airstrike/1848dbb81ac5eab5cd32 to your computer and use it in GitHub Desktop.
Excel: Autofit current column and make selected columns the same size as the largest of them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Sub AutoFit() | |
Dim Sht As Worksheet | |
Set Sht = ActiveSheet | |
With Selection | |
.EntireColumn.AutoFit | |
End With | |
If Selection.Columns.Count > 1 Then | |
With Application | |
Dim SU As Boolean | |
SU = .ScreenUpdating | |
.ScreenUpdating = False | |
Dim x As Long, max As Long | |
For x = 1 To Selection.Columns.Count | |
If Selection.Columns(x).ColumnWidth > max Then _ | |
max = Selection.Columns(x).ColumnWidth | |
Next | |
Dim r As Range | |
For x = 1 To Selection.Columns.Count | |
Set r = Selection.Columns(x) | |
r.ColumnWidth = max | |
Next | |
Application.ScreenUpdating = SU | |
End With | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment