Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Excel Macro – Autofit width and height

Posted on January 26, 2015August 27, 2024 By David Kittell

AutoFit() is designed to run in your Personal.xlsb with a keyboard function of Ctrl+d to select all columns and rows and then set a temporary width and height to then autofit based on all the content in the worksheet.

Sub AutoFit()
'
' AutoFit Macro
' Resize the column width to better contain the content.
'
' Keyboard Shortcut: Ctrl+d
'
Cells.Select
Selection.ColumnWidth = 95
Selection.RowHeight = 95
Selection.Columns.AutoFit
Selection.Rows.AutoFit
Range("A1").Select
End Sub
Sub AutoFit()
'
' AutoFit Macro
' Resize the column width to better contain the content.
'
' Keyboard Shortcut: Ctrl+e
'
Cells.Select
Range("A2").Activate
Selection.ColumnWidth = 100
Selection.RowHeight = 100
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.WrapText = True
.ShrinkToFit = True
End With
Selection.Rows.AutoFit
Selection.Columns.AutoFit
Range("A1").Select
End Sub

AutoFitHeight() is designed to run in your Personal.xlsb with a keyboard function of Ctrl+e to select all columns and rows and then autofit the height based on the all the content in the worksheet

Sub AutoFitHeight()
'
' AutoFitHeight Macro
'
' Keyboard Shortcut: Ctrl+e
'
Cells.Select
Selection.Rows.AutoFit
Range("A1").Select
End Sub
Originally Posted on January 26, 2015
Last Updated on August 27, 2024
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Excel

Post navigation

Previous post
Next post

Related Posts

C# Backup and Restore MySQL Database(s)

Posted on April 6, 2014October 26, 2015

Must Download DLLs from http://mysqlbackupnet.codeplex.com/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace MySQLBackupRestore { public partial class Form1 : Form { public static string sMySQLServer = "192.168.43.1"; public static string sMySQLUser = "root"; public static string sMySQLPassword = ""; public…

Read More

PHP Facebook WebCal Parse

Posted on March 18, 2015

I have seen various ways to parse webcal (ical, ics) files in PHP but they tend to get a little more complicated than they need to in some cases or simply do not work. <?phpPHP $icalURL = '<facebook URL>'; echo '<p>iCal URL:<br/>' . $icalURL . '</p>'; $ical = file_get_contents($icalURL); $sED_Start…

Read More

Run SQL Statement

Posted on August 1, 2013October 26, 2015

protected string sRunSQLStmnt(string sSQL) { string sReturn = ""; //Declare the connection object SqlConnection sqlConn = new SqlConnection(connString); int numberOfRecords = 0; try { //Make the connection sqlConn.Open(); //Declare the Command SqlCommand sqlCommand = new SqlCommand(sSQL + " SELECT @@ROWCOUNT AS DELETED;", sqlConn); //Execute the query numberOfRecords = sqlCommand.ExecuteNonQuery(); }…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes