|
Some useful Excel tips category 'KB', language VBA, created 30-Dec-2025, version V1.0, by Luc Pattyn with the assistance of Microsoft Copilot. |
|
License: The author hereby grants you a worldwide, non-exclusive license to use and redistribute the files and the source code in the article in any way you see fit, provided you keep the copyright notice in place; when code modifications are applied, the notice must reflect that. The author retains copyright to the article, you may not republish or otherwise make available the article, in whole or in part, without the prior written consent of the author. Disclaimer: This work is provided |
|
This Excel cheat sheet focuses on dynamic ranges, named values, and simple automation — the parts of Excel that turn a static sheet into a self maintaining system. This sheet will just touch those and give a few examples; it may grow over time. Note: some of this needs "Developer support", which is an Excel setting, not a workbook setting. To enable it, go to File Menu, Options, Customize Ribbon, and check "Developer". This will add a "Developer" menu (which you won't need to use explicitly as I suggest using keyboard combo's for it). |
Hotspots
|
Functions are documented alphabetically as well as by category.
Some useful ones include (with simplified descriptions):
| COUNTA(range) | Counts the non-empty cells in a range |
| INDEX(cell, dx, dy) | Points to the cell that is at position (cell.x+dx, cell.y+dy) Warning: there also is an INDEX variant that takes more parameters) |
| OFFSET(cell, dx, dy, h, w) | Returns a range that starts at INDEX(cell, dx, dy) and has size(w,h). Often used with dx=dy=0. Note the order of h and w! |
The "Name Manager" can be reached by hitting CTRL/F3. It acts like a store of key-value pairs, where the key is a named variable, the value any cell, constant, or calculation. The association is live, i.e. value gets evaluated whenever required.
Warning: Excel may stubbornly remember names that are no longer visible in the Name Manager, and force its user to come up with new names.
An elegant way to define the data of a line chart consists of these steps, assuming sheet1 with an ever growing table with columns A=date, B=value1, C=value2:
Some pro's for this approach are:
Macro's are user-defined functions that can be associated to buttons. They take three steps:
Warning: Excel will not save macro's in an .xlsx file; save as .xlsm and when asked, make the file a "Trusted Document" (which will have to be repeated when moving the file elsewhere).
Example VBA subroutine:
Option Explicit
Sub InsertColumnRelativeToButton()
Dim btn As Shape
Dim ws As Worksheet
Dim targetCol As Long
Set ws = ActiveSheet
' Identify the button that called this macro
Set btn = ws.Shapes(Application.Caller)
' Determine the column where the button is located, then
' add 1 since the button is in the right-most column that should NOT move.
targetCol = btn.TopLeftCell.Column + 1
' Insert a new column to the right of the button
ws.Columns(targetCol).Insert Shift:=xlToRight
' Copy formulas + formatting from the old column (now shifted right)
ws.Columns(targetCol + 1).Copy
ws.Columns(targetCol).PasteSpecial xlPasteFormats
ws.Columns(targetCol).PasteSpecial xlPasteFormulas
' Clear constants (keep formulas)
On Error Resume Next
ws.Columns(targetCol).SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
End Sub
An interesting article (in Dutch) on VBA performance: https://www.exhelp.be/vba/optimaliseer-de-snelheid-van-je-excel-macros-vba/
Perceler |
Copyright © 2012, Luc Pattyn |
Last Modified 28-Jan-2026 |