I have a shared Excel spreadsheet that many colleagues use and they change column size, zoom etc so I have created the following VBA code (connected to a button) so that it easily can be restored but for some reasons the column width wont work properly. In the sheet named "TOP" I want columns A:AJ to have 15 in width and AK:AL have 75 but for some reason Excel resizes AF:AL to 75 when it runs.
Columns("A:AJ").Select
Selection.ColumnWidth = 15
Columns("AK:AL").Select
Selection.ColumnWidth = 75
Any ideas why this happens? I have tried to add steps in the VBA where it moves to another sheet and comes back to the original sheet but no success.
Columns("A:AJ").Select
Selection.ColumnWidth = 15
Columns("AK:AL").Select
Selection.ColumnWidth = 75
Any ideas why this happens? I have tried to add steps in the VBA where it moves to another sheet and comes back to the original sheet but no success.
VBA Code:
Sub ResetSheets()
'
' ResetSheets Macro
'
'
Application.Calculation = xlManual
Sheets("TOP").Select
ActiveWindow.Zoom = 100
Columns("A:AJ").Select
Selection.ColumnWidth = 15
Columns("AK:AL").Select
Selection.ColumnWidth = 75
Range("A5").Select
ActiveCell.FormulaR1C1 = "TOTALT"
Range("B5").Select
Selection.ClearContents
Range("D5").Select
Selection.ClearContents
Range("E5").Select
ActiveCell.FormulaR1C1 = "100"
Range("F5").Select
ActiveCell.FormulaR1C1 = "JA"
Range("G5").Select
ActiveCell.FormulaR1C1 = "JA"
Range("H5").Select
ActiveCell.FormulaR1C1 = "NEJ"
Range("C:C").EntireColumn.Hidden = True
Range("A5").Select
ActiveSheet.PROTECT DrawingObjects:=True, Contents:=True, Scenarios:= _
False, AllowFormattingColumns:=True
Sheets("SÖK").Select
ActiveWindow.Zoom = 100
Columns("A:N").Select
Selection.ColumnWidth = 15
Range("B5").Select
Selection.ClearContents
Range("C:C").EntireColumn.Hidden = True
ActiveSheet.PROTECT DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True
Sheets("UPPF").Select
ActiveWindow.Zoom = 100
ActiveSheet.PROTECT DrawingObjects:=True, Contents:=True, Scenarios:= _
False, AllowFiltering:=True
Sheets("NYA").Select
ActiveWindow.Zoom = 100
ActiveSheet.PROTECT DrawingObjects:=True, Contents:=True, Scenarios:=False
Sheets("Data").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("INFO").Select
ActiveWindow.Zoom = 100
Range("A1").Select
Application.Calculation = xlAutomatic
End Sub
Last edited: